question about multi base classes

M

Michael

Hi,

A piece of description about multi inheritance in ISO/ANSI C++ standard is
as following:

A class shall not be specified as a direct base class of a derived class
more than once.
[Note: a class can be an indirect base class more than once and can be a
direct and an indirect base class. ]
Example:

class X { /* ... */ };
class Y : public X, public X { /* ... */ }; // illformed
class L { public: int next; /* ... */ };
class A : public L { /* ... */ };
class B : public L { /* ... */ };
class C : public A, public B { void f(); /* ... */ }; // wellformed
class D : public A, public L { void f(); /* ... */ }; // wellformed

if above class D is OK. why can't the following code be compiled with Visual
C++

#include "stdafx.h"
#include<iostream>
class v
{};
class b:public v
{};
class e:public v
{};
class d:public b,public v
{};
int main()
{ return 0;}

But the following code work well.

#include "stdafx.h"
#include<iostream>
class v
{};
class b:public v
{};
class e:public v
{};
class d:public b,public e
{};
int main()
{ return 0;}


thanks in advance
Michael
 
J

John Harrison

Michael said:
Hi,

A piece of description about multi inheritance in ISO/ANSI C++ standard is
as following:

A class shall not be specified as a direct base class of a derived class
more than once.
[Note: a class can be an indirect base class more than once and can be a
direct and an indirect base class. ]
Example:

class X { /* ... */ };
class Y : public X, public X { /* ... */ }; // illformed
class L { public: int next; /* ... */ };
class A : public L { /* ... */ };
class B : public L { /* ... */ };
class C : public A, public B { void f(); /* ... */ }; // wellformed
class D : public A, public L { void f(); /* ... */ }; // wellformed

if above class D is OK. why can't the following code be compiled with Visual
C++

#include "stdafx.h"
#include<iostream>
class v
{};
class b:public v
{};
class e:public v
{};
class d:public b,public v
{};
int main()
{ return 0;}

But the following code work well.

#include "stdafx.h"
#include<iostream>
class v
{};
class b:public v
{};
class e:public v
{};
class d:public b,public e
{};
int main()
{ return 0;}


thanks in advance
Michael

Once I'd removed #include "stdafx.h" both your examples compiled with my
copy of VC++ 7.1. The first one produced a warning but that is all.

If you think you've found a compiler bug you should take it up in a VC++
newsgroup (e.g. and state which version
you are using. Nothing wrong with either code sample that I can see.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,142
Messages
2,570,817
Members
47,363
Latest member
eitamoro

Latest Threads

Top