以下代码大致代表我正在处理的一些序列化内容,使用 g++ ( http://ideone.com/0rsGmt ) 编译,但 Visual Studio Express 2013 RC 失败并出现以下错误:
Error 1 error C2326: 'void foo::print(void)' : function cannot access 'foo::bar::member_'
Error 2 error C2039: 'bar' : is not a member of 'foo'
编码:
#include <iostream>
class foo
{
private:
struct bar
{
int member_;
};
public:
void print()
{
std::cout << sizeof(decltype(foo::bar::member_)) << std::endl;
}
};
int main(int argc, char* argv[])
{
foo f;
f.print();
return 0;
}
怎么了?Visual Studio 不足还是其他?显然我可以将结构声明移出类;Daniel Frey 在下面提供了一种解决方法;但我想知道为什么上面的代码不能用 Visual Studio 编译。
更新:接受的答案说它应该可以工作,但对于微软来说,它不是典型的。我在这里填写了一个错误报告:http ://connect.microsoft.com/VisualStudio/feedback/details/801829/incomplete-decltype-support-in-c-11-compiler
(如果有人可以为这个问题提出一个更好的标题,我将不胜感激!)