Via*_*rus 7 c++ struct prototype function
今天我遇到了这段代码:
int main() {
struct Foo {};
struct Bar {};
Foo(b)(int (Bar*c)); // ?
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我完全不知道发生了什么.我的编译器(VC14)警告我未使用的原型函数?
这行做什么(声明一个函数:哪个名称,什么参数和返回类型?如何调用它?)
Foo(b)(int (Bar*c));
Run Code Online (Sandbox Code Playgroud)
提前谢谢你的帮助!
这声明了一个名为的函数b:
int (Bar*c)作为参数;Foo.参数的类型int (Bar*c)是一个指向函数的指针,该函数接受指针Bar并返回一个int.这里c是参数的名称,可以省略:int (Bar*).
您可以通过以下方式致电b:
int main() {
struct Foo {};
struct Bar {};
Foo(b)(int (Bar* c)); // the prototype in question
int func(Bar*); // a function defined elsewhere
Foo result = b(func);
return 0;
}
Run Code Online (Sandbox Code Playgroud)