| | |
C++ Inheritance and Polymorphism
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 16
Reputation:
Solved Threads: 0
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
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
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.)
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.
![]() |
Similar Threads
- Polymorphism Homework Help (C++)
- Polymorphism/Non-Polymorphism (C++)
- inheritance, polymorphism, and other features (C++)
- Need example of how to use INHERITANCE! (C++)
- Quick Polymorphism Tutorial (C)
- Visual C++ (C++)
- Array limit (C)
- New To Programming = ME!! (C++)
Other Threads in the C++ Forum
- Previous Thread: Help fix my I/O problem?
- Next Thread: Converting different types to string, from included file, using templates
Views: 998 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






