8.3.5/8 Functions [dcl.fct]
says
[...] 函数的返回类型不得为
类型数组或function,尽管它们可能具有指针类型的返回类型或对此类事物的引用。 [...]
为什么规则这么明确?是否有某种语法甚至允许返回函数而不是函数指针?
我是否误解了这句话?
typedef void (*fp)();
void foo(){}
fp goo()
{
return foo; //automatically converted to function pointer
}
这是一个试图返回函数的函数的非常人为的示例:
void foo() { }
template<typename T>
T f() { return foo; }
int main(){
f<decltype(foo)>();
}
这是我从 Clang 3.2 得到的错误:
Compilation finished with errors:
source.cpp:7:5: error: no matching function for call to 'f'
f<decltype(foo)>();
^~~~~~~~~~~~~~~~
source.cpp:4:3: note: candidate template ignored: substitution failure
[with T = void ()]: function cannot return function type 'void ()'
T f() { return foo; }
~ ^
1 error generated.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)