-2

鉴于此代码:

#include <type_traits>
template<char ...Cs>
auto foo() -> typename std::enable_if<(sizeof...(Cs) > 1)>::type{
}

template<char C>
void foo() {
}

int main(){
    foo<'s'>();
}

我有上面的 c++ 程序,我只是想知道,根据标准中规定的规则,两个“foo”模板中的哪一个将被实例化用于 main.js 中的“foo”调用。

4

1 回答 1

0

您可以为每个打印件添加打印件以找出:

template<char ...Cs>
auto foo() -> typename std::enable_if<(sizeof...(Cs) > 1)>::type{
    cout << "1" << endl;
}
template<char C>
void foo() {
    cout << "2" << endl;
}
void EnableIfWithSizeof(){
    foo<'s'>();
}

int main() {
EnableIfWithSizeof();
return 0;
}

结果输出是2

于 2014-06-03T02:47:36.063 回答