當我using SFINAE with functions/function members在下列方式:克++汽車和類型名稱關鍵字
#include <type_traits>
#include <iostream>
#include <cstdlib>
struct X {};
struct A
{
template< typename T >
auto
f(T && x)
-> std::enable_if< std::is_same< T, X >::value >::type
{
return x;
}
};
int main()
{
return EXIT_SUCCESS;
}
我得到一個錯誤:
main.cpp:14:8: error: expected type-specifier
-> std::enable_if< std::is_same< T, X >::value >::type
^
main.cpp:14:8: error: expected initializer
這樣,我應該在前面加上推動者與typename
關鍵字。但是這裏根本沒有含糊之處:因爲我現在只在->
之後鍵入預期。另一個想法是Qt Creator的typename
關鍵字在這種情況下。
這是G ++錯誤?或者在C++ 11中有關於此類上下文的聲明typename
?
可能的重複[哪裏和爲什麼我必須把「模板」和「typename」關鍵字?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have -to-put-the-template-and-typename-keywords) –
@DanielFrey我在http://stackoverflow.com/questions/610245/找不到類似的上下文。 – Orient