1
我發現檢測類的成員使用全局模板功能不起作用:type_trait的有成員故障如果使用全局函數
void printinfo(std::true_type)
{
cout<<"true_type!";
}
void printinfo(std::false_type)
{
cout<<"false_type!";
}
class TestAA
{
public:
void foo();
};
class TestBB;
template<typename T,typename =decltype(&T::foo)>
std::true_type havefoo(T*){return{};}
std::false_type havefoo(...){return{};}
int main()
{
printinfo(havefoo((TestAA*)nullptr));
printinfo(havefoo((TestBB*)nullptr));
}
class TestBB
{
public:
void foo();
};
它無法檢測TestBB的富,是正常的嗎?或編譯器錯誤? gcc 4.8.1