question about multi base classes



 DEVELOP > c-Plus-Plus > question about multi base classes

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER