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. Advertisements

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:
    897
    Andrey Tarasevich
    Dec 1, 2003
  2. tomek
    Replies:
    3
    Views:
    1,045
    David Fisher
    Nov 30, 2003
  3. Chunhui Han
    Replies:
    2
    Views:
    742
  4. Alf P. Steinbach
    Replies:
    6
    Views:
    822
    John Carson
    Sep 3, 2005
  5. Replies:
    7
    Views:
    561
    Richard
    Aug 28, 2006
  6. Replies:
    11
    Views:
    908
    James Kanze
    Sep 10, 2006
  7. Hicham Mouline
    Replies:
    1
    Views:
    839
    Victor Bazarov
    Apr 20, 2009
  8. Karan Rajput
    Replies:
    2
    Views:
    311
    Abinoam Jr.
    Dec 22, 2010
Loading...