943,661 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1830
  • C++ RSS
Feb 27th, 2009
0

C++ Inheritance and Polymorphism

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dinomike1000 is offline Offline
16 posts
since Sep 2008
Feb 27th, 2009
2

Re: C++ Inheritance and Polymorphism

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.
Team Colleague
Reputation Points: 1133
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help fix my I/O problem?
Next Thread in C++ Forum Timeline: Converting different types to string, from included file, using templates





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC