Question:
C++: Is it possible for a parent function to access a member of a child function if you use a friend function?
Alex H
2012-01-07 19:16:49 UTC
I know that a parent function can't access members of a child function but a child function can access members of a parent function. However, if I use a friend function will this work?
Six answers:
Wertle Woo
2012-01-07 21:05:52 UTC
Parents can access public members of their children. If you want them to access protected or private members of the child, then the parent class must be declared to be a friend of the child class, or the specific function in the parent class needs to be declared to be a friend function of the child class. I don't know what situation you could be in that would require this, but it sounds like you might want to re-evaluate your sloppy design if it's creating the need for this.
Silent
2012-01-07 19:36:42 UTC
It's a little hard to follow your question because you seem to be mixing up the terms "function" and "class" a bit.



You also seem to have some misconceptions about inheritance. It's not that a child class can "access" functions from its parent class. A child class actually has the functions from its parent class. The child class is a subtype of the parent class.
green meklar
2012-01-08 10:30:13 UTC
What exactly is meant by a 'parent function', 'child function' and 'friend function'? Are you sure you're not referring to classes, rather than functions?
2017-01-09 23:07:51 UTC
great selection: on your conflict classification you may want a public setAttackCounter carry out, which you will possibly call out of your attack classification. 2nd selection: Mkae the variable secure. classification wrestle coated: // coated awareness aspects additionally would be on the instant accessed by ability of subordinate training int AttackCounter; ;
Mr. Shar Pei
2012-01-08 19:54:32 UTC
Student programming services at helpwithprogramming.com
2012-01-07 19:26:10 UTC
Why not try?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...