Two objects created in a Single class

2

2005

Hi

I have a situation that I created two objects in a Single class, say

CAll All_A, All_B;

I can access the public functions within them without the "."
operation, say public function Display(), Term() ; inside Display(), I
can do Term() { not All_A.Term() } since they are member functions.

The issue is I have All_A & All_B - how do I differentiate them?

Am I supposed to do
All_B.Term() just to differentiate them?

Thanks
 
D

David Harmon

On 27 Oct 2006 18:29:54 -0700 in comp.lang.c++, "2005"
Hi

I have a situation that I created two objects in a Single class, say

CAll All_A, All_B;

I can access the public functions within them without the "."
operation, say public function Display(), Term() ; inside Display(), I
can do Term() { not All_A.Term() } since they are member functions.

The issue is I have All_A & All_B - how do I differentiate them?

Am I supposed to do
All_B.Term() just to differentiate them?


When you call Term() inside CAll::Display(), it is the same as
this->Term(). It is called as a member function of the same object.
So All_A.Display() will end up calling Term() upon All_A, and
ALL_B.Display() will end up calling Term() upon All_B.

As soon as you have three objects you had better start thinking
about std::vector<CAll>.
 
2

2005

David said:
On 27 Oct 2006 18:29:54 -0700 in comp.lang.c++, "2005"



When you call Term() inside CAll::Display(), it is the same as
this->Term(). It is called as a member function of the same object.
So All_A.Display() will end up calling Term() upon All_A, and
ALL_B.Display() will end up calling Term() upon All_B.

Am I right to assume that inside the member function, I call
ALL_B.Display() & All_A.Display() since there 2 objs ( and it would be
redundant if there are only one object ).
 
D

David Harmon

On 27 Oct 2006 19:42:07 -0700 in comp.lang.c++, "2005"
Am I right to assume that inside the member function, I call
ALL_B.Display() & All_A.Display() since there 2 objs

I don't know; what are you trying to accomplish? I certainly don't
see any reason to call both of them from within some other member
function, but you might have a reason.
( and it would be redundant if there are only one object ).

No, with only one object you certainly cannot call functions of two
objects.

Post a small but complete compilable sample of the code you are
trying to use.
 

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
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top