We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,231 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Interacting with derived class's functions from the base class

If I wanted to access a function that is in a derived class from it's base class, what would be the best way of doing so? I have experimented with functions like Interact( char *pCommand, char **pArgs ) which is inside the base class, and can be overidden by the derived class to access it's functions. But that doesn't really seem like the best way to do so. Can someone give me a suggestion or two as to what the best way to do this is. If you need a better explanation of what I'm trying to do, just ask.

2
Contributors
1
Reply
28 Minutes
Discussion Span
3 Years Ago
Last Updated
2
Views
godflesh231
Newbie Poster
5 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

The base class knows nothing about the existence of child classes, and should never even want to know.
If you think you have such a requirement, you have a fundamentally flawed design.

But most likely all you need are some virtual functions, which would make the whole thing happen implicitly, so the correct overridden function from a child class gets called from a non-overridden method in the base class when that method is used from an instance of that child class.

jwenting
duckman
Team Colleague
8,522 posts since Nov 2004
Reputation Points: 1,656
Solved Threads: 345
Skill Endorsements: 19

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0594 seconds using 2.7MB