-
May 30th, 2009, 06:52 AM
#1
Parent class to call children method
Hello all,
I am looking for elegant way to call children's method from parent class,
is at possible at all?
Thanks
-
May 30th, 2009, 07:32 AM
#2
Re: Parent class to call children method
Use virtual functions if they're appropriate. A parent class shouldn't have any knowledge of classes derived from it.
-
May 30th, 2009, 02:00 PM
#3
Re: Parent class to call children method
if the parent has declared a virtual, and the parent calls that method somewhere in the class, it will actually call the child class's override of the virtual. oops, just like gcdef said.
otherwise you might need to start thinking about call back maps etc.
Last edited by Amleto; May 30th, 2009 at 02:03 PM.
-
May 30th, 2009, 02:35 PM
#4
Re: Parent class to call children method
Gcdef,Amleto, thanks for your advise,
so after some googling I found a solution that seems nice - using private inheritance
and pure virtual functions at the base class.
http://www.parashift.com/c++-faq-lit....html#faq-24.3
-
May 30th, 2009, 02:47 PM
#5
Re: Parent class to call children method
Originally Posted by smishash
I don't see that private inheritance and pure virtuals buy you anything in this case. public inheritance and regular virtual functions should do what you need.
-
May 30th, 2009, 03:00 PM
#6
Re: Parent class to call children method
Originally Posted by GCDEF
I don't see that private inheritance and pure virtuals buy you anything in this case. public inheritance and regular virtual functions should do what you need.
- shure, i just liked their way to "defence" themselves from unwanted deeper inheritance :-)
-
May 30th, 2009, 03:59 PM
#7
Re: Parent class to call children method
Originally Posted by smishash
- shure, i just liked their way to "defence" themselves from unwanted deeper inheritance :-)
Why?
-
June 2nd, 2009, 03:41 AM
#8
Re: Parent class to call children method
Code:
class Measurement : private Feedback {
protected:
public:
Measurement *_feedbck;
char* str_out;
Actually you coding composition.
Thanks for your help.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|