coo*_*451 12 c++ compile-time constant-expression
有没有办法在常量表达式中使用函数地址?
void foo()
{}
int main()
{
static_assert(&foo, "test error");
}
Run Code Online (Sandbox Code Playgroud)
这不会编译.
错误C2057:预期的常量表达式
这背后的意图是我想在编译时比较两个函数地址.
它绝对是一个编译器错误.
函数可以用作模板的模板参数,这意味着它们是const表达式.(见ideone).
此外,上面的代码编译很好gcc 4.6.1,虽然ideone不编译它,但ideone使用gcc-4.5.1哪个有关于您的代码的错误.