use*_*370 14 c++ typeof scope-resolution decltype c++11
有了像Foo这样的课程:
struct Foo { static const int i = 9; };
Run Code Online (Sandbox Code Playgroud)
我发现GCC 4.5将拒绝以下内容
Foo f;
int x = decltype(f)::i;
Run Code Online (Sandbox Code Playgroud)
如果我使用中间typedef,它将起作用,例如:
typedef decltype(f) ftype;
int x = ftype::i;
Run Code Online (Sandbox Code Playgroud)
但我更喜欢保持命名空间的清洁.我认为优先权可能是一个问题,所以我也试过括号,但没有运气.它是不可能的,或者是否有一段语法可以帮助我?
Joh*_*itb 13
这是有效的C++ 0x decltype(f)::i.GCC还不支持它.您可以使用身份模板进行处理
template<typename T> struct identity { typedef T type; };
int x = identity<decltype(f)>::type::i;
Run Code Online (Sandbox Code Playgroud)
identity是boost::mpl命名空间的一部分.