| | |
C++ Inheritance and Polymorphism
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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
| Thread Tools | Search this Thread |
api application array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int integer java lib linux loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct studio template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






