クラスが継承リストにdecltype
を持つことができないのはなぜですか?例えば、私は次のコードは、RType
からA<B>
継承を行うことを期待するが、G ++ 4.6.1(-std=c++0x
を使用)と、それはコンパイルされません:クラスが宣言型の結果から継承できないのはなぜですか?
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
:
#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;
}
それは次のような出力を提供します
declval
を使用すると、decltype
を使用する必要があるインスタンスを提供するだけですが、decltype
のその他の使用も失敗します(つまり、declval
なし)。
gcc 4.7、clangまたは他のコンパイラを試しましたか? gccはまだ完全にC++ 11に準拠していません... – PlasmaHH
@PlasmaHH私は実際に(他の理由で)clangをコンパイルしようとしていますが、MSVC++ 2010では動作しません。 –