[英]type_trait 's have member Failure if use global function
我發現detect類的成員使用全局模板函數不起作用:
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的foo,是正常的嗎? 還是編譯錯誤? gcc 4.8.1
編譯器還沒有見過的定義TestBB
在調用的點printinfo
,只有向前聲明。 那時它不知道TestBB
任何成員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.