| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Michael" |
| Date: |
28 Aug 2003 04:42:08 PM |
| Object: |
question about multi base classes |
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
.
|
|
| User: "John Harrison" |
|
| Title: Re: question about multi base classes |
29 Aug 2003 12:28:54 AM |
|
|
"Michael" <michael-chen@sympatico.ca> wrote in message
news:AFu3b.10483$nw3.339240@news20.bellglobal.com...
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. news:microsoft.public.vc.language) and state which version
you are using. Nothing wrong with either code sample that I can see.
john
.
|
|
|
|

|
Related Articles |
|
|