class problem

F

Frank Steinicke

Hello ng,

i have the following (object orientated) problem:

i have 2 classes, "Class1" and "Class2".
Now "Class1" calls a function "func" of the "Class2".

Is it possible to know out of the "Class2", which class called the
function "func" ?

And how do you realise this ?

Thanks and best regards, frank
 
R

Ron Natalie

Frank Steinicke said:
Is it possible to know out of the "Class2", which class called the
function "func" ?

No. C++ functions (member or otherwise) have no
inate idea of how they were called.
And how do you realise this ?

You need to pass in what ever information the called function needs
as an argument.
 
B

Buster Copley

Frank said:
i have the following (object orientated) problem:

i have 2 classes, "Class1" and "Class2".
Now "Class1" calls a function "func" of the "Class2".

Is it possible to know out of the "Class2", which class called the
function "func" ?

And how do you realise this ?

This reminds me of Borland's VCL, where functions used as event
callbacks have 'TObject * Sender' as their first parameter. These
functions then know from which object they were called. To get
the class would typically require RTTI.

I don't know if this is any help to you. Good luck.

Regards,
Buster.
 
M

Mr E Mann

Pass a reference to Class1 into Class2 when you instantiate Class2.
Otherwise, the answer to your question is no.
 

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

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top