error C2332: 'enum' : missing tag name

环境;win7 32,vs2013

代码:

#include <iostream>
using namespace std;

namespace MYSPACE{
	enum class choice
	{
		rock,
		paper,
		scissors
	};
}
typedef MYSPACE::choice Mchoice;

int main()
{
	Mchoice c = Mchoice::rock;
	return 0;
}

报错:

1>d:\hbj\test\test0505\test0505\t.cpp(5): error C2332: 'enum' : missing tag name
1>d:\hbj\test\test0505\test0505\t.cpp(6): error C2236: unexpected 'class' 'MYSPACE::choice'. Did you forget a ';'?
1>d:\hbj\test\test0505\test0505\t.cpp(6): error C3381: 'MYSPACE::choice' : assembly access specifiers are only available in code compiled with a /clr option
1>d:\hbj\test\test0505\test0505\t.cpp(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\hbj\test\test0505\test0505\t.cpp(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\hbj\test\test0505\test0505\t.cpp(10): error C2143: syntax error : missing ';' before '}'
1>d:\hbj\test\test0505\test0505\t.cpp(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\hbj\test\test0505\test0505\t.cpp(18): error C2039: 'rock' : is not a member of 'MYSPACE::choice'
1>          d:\hbj\test\test0505\test0505\t.cpp(6) : see declaration of 'MYSPACE::choice'
1>d:\hbj\test\test0505\test0505\t.cpp(18): error C2065: 'rock' : undeclared identifier

原因:vs2013使用了vs2010库,而vs2010不支持c++0x新增的强类型enum class

解决:在vs2013项目属性里,General->Platform Toolset,选择Visual Studio 2013 - Windows XP (v120_xp)或者Visual Studio 2013

参考:http://blog.csdn.net/zhanglei5415/article/details/1588258

http://zhidao.baidu.com/link?url=OTbxL2KFkfdunxC1dspL7dsa31zKQbHz-_kj6ZaB8O6TDhbpRmUyUqGUTV_DVr8pGS3msaXxxCg9i1aqXguMLd_i7YGP-XZEy62ELU2Utwm

http://blog.csdn.net/u012333003/article/details/20612267?utm_source=tuicool

http://www.cnblogs.com/tekkaman/p/3500904.html

http://www.xuebuyuan.com/1390932.html

http://blog.jobbole.com/44015/

你可能感兴趣的:(enum,Class,强类型,c++0x)