2016-05-09 13 views
1

In einem Versuch, SFINAE zu verwenden, schlägt der folgende Code zu kompilieren:decltype und statische Template-Methode

template<typename ObjectType, typename GroupA, typename GroupB, typename = void> 
struct DelegateImpl; // default version 

template<typename ObjectType, typename GroupA, typename GroupB> 
struct DelegateImpl<ObjectType, GroupA, GroupB, decltype(GroupA::get<ObjectType>())>; // specialization 

Mit GCC:

error: template argument 4 is invalid

Mit MSVC, eine überraschend hilfreicher:

error C3553: decltype expects an expression not a type

Mein Ziel ist es, den Compiler wählen Sie die Spezialisierung, wenn der Ausdruck GroupA::get<ObjectType>() gültig ist.

Frage: Wie benutze ich declltype mit einer statischen Template-Methode?

+0

Mögliche Duplikat: [Wo und warum muss ich die „Vorlage“ setzen und „Typname“ Schlüsselworte?] (http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typeam-keywords). –

Antwort

5

Weder Compiler geben tatsächlich hilfreiche Fehler. Das eigentliche Problem ist, du verpasst die template Schlüsselwort vor get:

template get<ObjectType>() 

Siehe cppreference Seite auf Dependent Names

Verwandte Themen