virtual base class overhead

Discussion in 'C++' started by Thomas Maier-Komor, Oct 20, 2004.

  1. Hi,

    let's assume there is an abstract base class (ABC), which is
    inheritet virtually by two classes (A,B). A and B themselves
    are inheritet by another class (C). What kind of overhead
    should I expect compared to a class X, which implements
    the virtual functions of the base classes directly without
    an additional inheritance layer? Is it compiler dependent or
    are there any fundamental tradeoffs with the implementation
    of class C?

    Thanks,

    Tom


    struct ABC
    {
    virtual int foo() = 0;
    virtual float bar() = 0;
    };

    struct A : public virtual ABC
    {
    int foo()
    { return 0; }
    };

    struct B : public virtual ABC
    {
    float bar()
    { return 0; }
    };

    struct C : public A, public B
    {

    };

    struct X : public ABC
    {
    int foo()
    { return 0; }
    float bar()
    { return 0; }
    };
    Thomas Maier-Komor, Oct 20, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tomek
    Replies:
    2
    Views:
    676
    Andrey Tarasevich
    Dec 1, 2003
  2. tomek
    Replies:
    3
    Views:
    745
    David Fisher
    Nov 30, 2003
  3. Chunhui Han
    Replies:
    2
    Views:
    503
  4. Replies:
    7
    Views:
    378
    Richard
    Aug 28, 2006
  5. Replies:
    11
    Views:
    692
    James Kanze
    Sep 10, 2006
Loading...

Share This Page