using-declaration

Class declaration in same scope as using declaration compiles in GCC but not MSVS

Deadly 提交于 2019-11-29 07:37:57
Is the following program well-formed according to the c++ standard? namespace X { class A; } namespace Y { using X::A; class A {}; } int main() {} I'm getting different results with different compilers: gcc compiles it without errors. visual c++ gives error C2888: 'X::A': symbol cannot be defined within namespace 'Y' I don't find any rule in the c++ standard that my program violates. If the program is well-formed, why does visual studio give an error? If the program is not well-formed, what rule in the c++ standard did it violate and why doesn't gcc give an error? I'm not trying to make my

Class declaration in same scope as using declaration compiles in GCC but not MSVS

流过昼夜 提交于 2019-11-28 01:07:39
问题 Is the following program well-formed according to the c++ standard? namespace X { class A; } namespace Y { using X::A; class A {}; } int main() {} I'm getting different results with different compilers: gcc compiles it without errors. visual c++ gives error C2888: 'X::A': symbol cannot be defined within namespace 'Y' I don't find any rule in the c++ standard that my program violates. If the program is well-formed, why does visual studio give an error? If the program is not well-formed, what

using declaration with enum?

北慕城南 提交于 2019-11-26 23:36:19
问题 using declaration does not seem to work with enum type class Sample{ public: enum Colour { RED,BLUE,GREEN}; } using Sample::Colour; does not work!! do we need to add using declaration for every enumerators of enum type? like below using sample::Colour::RED; 回答1: A class does not define a namespace, therefore "using" isn't applicable here. Also, you need to make the enum public. If you're trying to use the enum within the same class, here's an example: class Sample { public: enum Colour { RED,

What is the difference between 'typedef' and 'using' in C++11?

ぐ巨炮叔叔 提交于 2019-11-25 22:46:42
问题 I know that in C++11 we can now use using to write type alias, like typedef s: typedef int MyInt; Is, from what I understand, equivalent to: using MyInt = int; And that new syntax emerged from the effort to have a way to express \" template typedef \": template< class T > using MyType = AnotherType< T, MyAllocatorType >; But, with the first two non-template examples, are there any other subtle differences in the standard? For example, typedef s do aliasing in a \"weak\" way. That is it does