Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c++ - Scope resolution operator on enums a compiler-specific extension?

On this question, there's an answer that states:

You can use typedef to make Colour enumeration type accessible without specifying it's "full name".

typedef Sample::Colour Colour;
Colour c = Colour::BLUE;

That sounds correct to me, but someone down-voted it and left this comment:

Using the scope resolution operator :: on enums (as in "Colour::BLUE") is a compiler-specific extension, not standard C++

Is that true? I believe I've used that on both MSVC and GCC, though I'm not certain of it.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

I tried the following code:

enum test
{
    t1, t2, t3
};

void main() 
{
    test t = test::t1;
}

Visual C++ 9 compiled it with the following warning:

warning C4482: nonstandard extension used: enum 'test' used in qualified name

Doesn't look like it's standard.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...