How optimized is inheritance? (C++)

Programming, for all ages and all languages.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

How optimized is inheritance? (C++)

Post by earlz »

I know virtual functions add overhead, but for the highest level of an inheritance tree, will it add any overhead?

like would

Code: Select all

class base{
  virtual bah();
};

class up1: base{
  virtual bah();
};

class up2: base{
 virtual bah();
};


void main(base* low, up1* up){
  low->bah(); //I know this will produce overhead
  up->bah(); //but will this!?
}

User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: How optimized is inheritance? (C++)

Post by Candy »

Code: Select all

class base{
  virtual bah();
};

class up1: base{
  virtual bah();
};

class up2: base{
 virtual bah();
};

void func(base* low, up1* up){
  low->bah(); //I know this will produce overhead
  up->bah(); //but will this!?
}

class up3 : pubilc up1 { virtual bah(); };
int main() {
  func(new low(), new up3());
}
If it didn't, the addition would fail to work.

Please don't modify main's signature - it was fine & dandy with argc and argv.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

lol...yea, your right...was typing without thought really..
Post Reply