Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

c++ - forward/strong enum in VS2010

At http://blogs.msdn.com/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx there is a table showing C++0x features that are implemented in 2010 RC. Among them are listed forwarding enums and strongly typed enums but they are listed as "partial". The main text of the article says that this means they are either incomplete or implemented in some non-standard way.

So I've got VS2010RC and am playing around with the C++0x features. I can't figure these ones out and can't find any documentation on these two features. Not even the simplest attempts compile.


enum class E { test };
int main() {}

fails with:

1>e:dev_workspaceexperimental2010_feature_assessment2010_feature_assessmentmain.cpp(518): error C2332: 'enum' : missing tag name
1>e:dev_workspaceexperimental2010_feature_assessment2010_feature_assessmentmain.cpp(518): error C2236: unexpected 'class' 'E'. Did you forget a ';'?
1>e:dev_workspaceexperimental2010_feature_assessment2010_feature_assessmentmain.cpp(518): error C3381: 'E' : assembly access specifiers are only available in code compiled with a /clr option
1>e:dev_workspaceexperimental2010_feature_assessment2010_feature_assessmentmain.cpp(518): error C2143: syntax error : missing ';' before '}'
1>e:dev_workspaceexperimental2010_feature_assessment2010_feature_assessmentmain.cpp(518): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



int main()
{
  enum E : short;
}


Fails with:
1>e:dev_workspaceexperimental2010_feature_assessment2010_feature_assessmentmain.cpp(513): warning C4480: nonstandard extension used: specifying underlying type for enum 'main::E'
1>e:dev_workspaceexperimental2010_feature_assessment2010_feature_assessmentmain.cpp(513): error C2059: syntax error : ';'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So it seems it must be some totally non-standard implementation that has allowed them to justify calling this feature "partially" done. How would I rewrite that code to access the forwarding and strong type feature?

Some further information about the new features I'm attempting to use:

Strongly typed enums: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf

Forward declaration of enums: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think I found the answer. I found "enum class" in the VS 2010 documentation under the keywords documentation. It's managed only--unsupported in real C++ builds. So it seems that they mean this C++0x feature is "partially done" in that it isn't done at all.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...