Reputation: 7506
Is the following legal C++ code:
class C
{
static public int x;
};
It compiles OK in Visual Studio 2008 C++ and Visual Studio 2010 C++ (beta 2). But the static member x does not end up being public.
In Visual Studio 2010 beta 2 the experience is even stranger. Intellisense reports an error "expected an identifier", but the compiler does not. Visual Studio 2008 does not give any error.
So the questions are:
Is this legal C++ code? What does it mean?
Upvotes: 2
Views: 997
Reputation: 43575
It's not legal C++ code.
The 'public' isn't allowed in variable declarations. What you're seeing however is that the compiler 'works' because it also compiles as CLI (.NET code) and there it's allowed and legal.
Upvotes: 4
Reputation: 264411
No it is not legal C++
It may be legal C# (but you would need to check with a C# person).
Upvotes: 2
Reputation: 19114
This is not legal C++. It is a legal C#, so that's why MS IDE bugged out.
Correct:
public: static int x;
Upvotes: 6