Perché una classe non può avere un decltype
nell'elenco ereditari? Per esempio, mi sarei aspettato il seguente codice per rendere A<B>
ereditare da RType
, ma con G ++ 4.6.1 (usando -std=c++0x
) che non può essere compilato:Perché una classe non può ereditare dal risultato di un decltype?
#include <type_traits>
template<typename T>
class A : public decltype(std::declval<T>().hello()) { };
class RType { };
class B {
public:
RType hello() { return RType(); }
};
int main() {
A<B> a;
}
E ha pronunciato la seguente uscita:
test.cpp:6:18: error: expected class-name before 'decltype'
test.cpp:6:18: error: expected '{' before 'decltype'
test.cpp:6:54: error: expected unqualified-id before '{' token
test.cpp: In function 'int main()':
test.cpp:16:7: error: aggregate 'A<B> a' has incomplete type and cannot be defined
L'uso di declval
è solo per fornire un'istanza in cui è necessario utilizzare decltype
, ma anche altri usi di decltype
non riescono (ovvero senza declval
).
Hai provato gcc 4.7, clang o qualsiasi altro compilatore? gcc non è completamente compatibile con C++ 11 ... – PlasmaHH
@PlasmaHH Attualmente sto provando a compilare clang ora (per altri motivi) ma con MSVC++ 2010 non funziona. –