C++ inheritance ambiguity

Here’s something fun I discovered today:


class a {
public:

class b {
public:
virtual void dosomething() = 0;
};
};

class c : public a::b {
public:

class b {
public:
virtual void dosomethingelse() = 0;
};

void dosomething() {}
};

class d : public c::b {
public:

void dosomethingelse() { printf ("do something else\n"); }
void dosomething() { printf ("do something\n"); }
};

void main()
{
d *foo = new d();
c::b *myfoo = reinterpret_cast(foo);
myfoo->dosomethingelse();
}

With Visual Studio .NET 2003 you’ll see “do something” on the console. With GCC you’ll see “do something else”. In fact, with GCC you don’t even need the reinterpret_cast.

Where did my C/C++ settings go in Visual Studio?

This is crazy!

A while ago I noticed that the “C/C++” settings block in one of my Visual Studio projects disappeared. I couldn’t change any compilation settings in my project unless I made the changes on a per-file basis, which is really annoying when your project has over a hundred files in it, so I just did without. Well today I needed to change something so I set out to correct the problem.

After an hour mucking with the .vcproj file trying to figure out what happened, I finally discovered something: take all .c and .cpp files your project and the “C/C++” settings block disappears. Well, here’s what happened: in the studio where I work they don’t use .cpp for C++ files, they use .cc.

Add a single .cpp file back to your project and (tada!) you have your C/C++ settings again. *sigh*