我不明白为什么该语句test()()要调用函数调用运算符。
#include <iostream>
#include <thread>
using namespace std;
class test{
public:
test(){
cout<<"i am in constructor"<<endl;
}
void operator() (){
cout<<"i am in an overloaded function"<<endl;
}
};
int main()
{
test t;
test()();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出 -
#include <iostream>
#include <thread>
using namespace std;
class test{
public:
test(){
cout<<"i am in constructor"<<endl;
}
void operator() (){
cout<<"i am in an overloaded function"<<endl;
}
};
int main()
{
test t;
test()();
return 0;
}
Run Code Online (Sandbox Code Playgroud)