Really strange compiler behaviour

I (accidentally) had code along the lines of this:

1
2
3
4
5
6
7
8
9
10
11
12
13
class foo {};

class bar {
public:
   foo x;

   void doStuff ();
};

void bar::doStuff () {
   foo x = new foo ();
// Try to do something intelligent and fail miserably...
}


The question is: Why does this compile/what on earth is it doing??
The code should not compile. new foo () returns a pointer so x has to be a pointer.

 
foo* x = new foo ();

The x in doStuff is not related to the x class member variable - it shadows it.
Topic archived. No new replies allowed.