[英]C++0x decltype and the scope resolution operator
With a class such as Foo: 有了像Foo这样的课程:
struct Foo { static const int i = 9; };
I find that GCC 4.5 will reject the following 我发现GCC 4.5将拒绝以下内容
Foo f;
int x = decltype(f)::i;
It will work if I use an intermediate typedef, such as: 如果我使用中间typedef,它将起作用,例如:
typedef decltype(f) ftype;
int x = ftype::i;
but I prefer to keep the namespace clean. 但我更喜欢保持名称空间清洁。 I thought precedence may be an issue, so I've also tried parentheses, but no luck.
我认为优先权可能是一个问题,所以我也试过括号,但没有运气。 Is it impossible as presented, or is there a piece of syntax that can help me?
它是不可能的,或者是否有一段语法可以帮助我?
It is valid C++0x to say decltype(f)::i
. 说
decltype(f)::i
是有效的C ++ 0x。 GCC just doesn't support it yet. GCC还不支持它。 You can work it around with an identity template
您可以使用身份模板进行处理
template<typename T> struct identity { typedef T type; };
int x = identity<decltype(f)>::type::i;
identity
is part of the boost::mpl
namespace. identity
是boost::mpl
名称空间的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.