Page 1 of 1

How optimized is inheritance? (C++)

Posted: Sun Jul 01, 2007 11:27 am
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!?
}


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

Posted: Sun Jul 01, 2007 12:42 pm
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.

Posted: Sun Jul 01, 2007 6:36 pm
by earlz
lol...yea, your right...was typing without thought really..