C++ Inheritance and Polymorphism

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 16
Reputation: Dinomike1000 is an unknown quantity at this point 
Solved Threads: 0
Dinomike1000 Dinomike1000 is offline Offline
Newbie Poster

C++ Inheritance and Polymorphism

 
0
  #1
Feb 27th, 2009
Hello - I have a question about inheritance and polymorphism in C++. If one is making heavy use of inheritance and using a lot of pure virtual and plain virtual functions, are there any common practices for avoiding having the virtual functions staggered in confusing ways.

By that I mean having multiple classes in an inheritance chain and having overrides of virtual functions at different places along the chain.

Thanks,

Mike
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C++ Inheritance and Polymorphism

 
2
  #2
Feb 27th, 2009
Yes. Never override any implementation with a different implementation. Only override pure virtual functions. Use composition to parameterize your instances instead of using inheritance -- "never" use protected virtual functions, overriding them in subclasses, to parameterize a class's behavior. Instead, make a separate datatype that performs the method's computation and pass it in as a parameter.

You should never be making "heavy" use of inheritance. (But I'm not sure what your standards of "heavy" are.)
Last edited by Rashakil Fol; Feb 27th, 2009 at 11:19 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC