question about multi base classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael

    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<iostre am>
    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<iostre am>
    class v
    {};
    class b:public v
    {};
    class e:public v
    {};
    class d:public b,public e
    {};
    int main()
    { return 0;}


    thanks in advance
    Michael


  • John Harrison

    #2
    Re: question about multi base classes


    "Michael" <michael-chen@sympatico. ca> wrote in message
    news:AFu3b.1048 3$nw3.339240@ne ws20.bellglobal .com...[color=blue]
    > 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[/color]
    Visual[color=blue]
    > C++
    >
    > #include "stdafx.h"
    > #include<iostre am>
    > 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<iostre am>
    > class v
    > {};
    > class b:public v
    > {};
    > class e:public v
    > {};
    > class d:public b,public e
    > {};
    > int main()
    > { return 0;}
    >
    >
    > thanks in advance
    > Michael
    >[/color]

    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.langu age) and state which version
    you are using. Nothing wrong with either code sample that I can see.

    john


    Comment

    Working...