number of children exist?

V

Victor Bazarov

Hi
I have a mother class, and a child class. Can i know how man object
of child exist from the mother class?

The "mother class" (whatever you mean by it) should have either a record
or a memory about giving birth to each "child". Counting the records or
remembering (extracting from memory) should give you the child count.

In any way, C++ has no concept of "mother" or "child". What exactly do
you mean by those?

V
 
P

Phlip

cmk128 said:
I have a mother class, and a child class. Can i know how man object
of child exist from the mother class?

Please post some code. The jargon "mother" and "child" can mean many
different things.

If you mean "base" and "derived classes", you can't know the number.
 
O

osmium

I have a mother class, and a child class. Can i know how man[y]
object
of child exist from the mother class?


Add a protected data member to the base class. In the constructor for the
derived class, increment the count contained in the parent. If you're a
worry wart you can make it more complicated.
 
C

cmk128

osmium 寫é“:
I have a mother class, and a child class. Can i know how man[y]
object
of child exist from the mother class?


Add a protected data member to the base class. In the constructor for the
derived class, increment the count contained in the parent. If you're a
worry wart you can make it more complicated.


Thanks osmimum
Instead of a count, can i add give the pointer of the current
object of the drived class to it's parent class? So the parent class
can reference all their child class's object?

thanks
from Peter
 
O

osmium

I have a mother class, and a child class. Can i know how man[y]
object
of child exist from the mother class?


Add a protected data member to the base class. In the constructor for the
derived class, increment the count contained in the parent. If you're a
worry wart you can make it more complicated.


Instead of a count, can i add give the pointer of the current
object of the drived class to it's parent class? So the parent class
can reference all their child class's object?

I don't know of any reason that couldn't be done. It's getting complicated
enough that I would put a member function in the base class to handle the
details of adding. The function would add the newly received pointer to a
stack or vector of such pointers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top