【发布时间】:2015-09-30 18:21:22
【问题描述】:
所以我有以下在 VS2012 下完美运行的代码。它检测是否存在全局函数“Bar”。
遗憾的是,在 clang 3.5 下编译失败并出现此错误:
error : use of undeclared identifier 'Bar'
template <typename T> static int Foo( decltype( Bar )* ) { return 2; }
^
clang 是否支持这种事情,如果支持,正确的语法是什么?
谢谢
template <typename T> static int Foo( decltype( Bar )* ) { return 2; }
template <typename T> static int Foo(...) { return 1; }
void main()
{
printf("%d", Foo<int>(nullptr));
}
【问题讨论】:
-
不。那不应该编译
-
“全局”函数还是全局函数?
-
这是一个 VS 错误。代码不合法。 SFINAE 中的 SF 代表替换失败。此代码在进行任何替换之前失败,即在模板定义处。
-
那么如何使用 Clang 找出函数是否存在(注意。不是成员函数)?
-
@user176168 你可能对this question感兴趣。