我想实现以下内容:
我定义了一个函数.当我在函数后写N 时(),函数将被调用N次.
我举个例子:
#include <iostream>
using namespace std;
typedef void* (*c)();
typedef c (*b)();
typedef b (*a)();
a aaa()
{
cout<<"Google"<<endl;
return (a)aaa;
}
int main()
{
aaa()()()();
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
然后输出是:

还有其他方法可以实现吗?
使用仿函数很简单.
#include <iostream>
struct Function
{
Function& operator()() {
std::cout << "Google" << std::endl;
return *this;
}
};
int main()
{
Function f;
f()()()();
}
Run Code Online (Sandbox Code Playgroud)