pass data from one class to another

How will i pass a string from one class to another.
Here is a sample code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#nclude "Reveiver"
class Sender
{
public:
    void send(Receiver *rec)
    {
        rec->receive(myString);
    }
    string getString() const
    {
        return myString;
    }
private:
    string myString;
};


/***************************/

class Receiver
{
public:
    void receive(string str)   
    {
        R_string = str;
    }
private:
    string R_string;
};

/*************************/
int main()
{
    //assume these objects
    *ReceiverObj;
    *Senderobj;
    
    SenderObj->send(ReceiverObj);
    cout<<ReceiverObj->getString()<<endl;

}


cout<<ReceiverObj->getString() prints an empty string.
Im suspecting that Sender::myString is not successfully passed through to Receiver::receive(str)

If this is the case, how can i pass the string from one class to a function in another.
On the face of it, it seems like it should work (assuming you have getString() defined for Receivers). Could you produce a minimal compilable example with the problem?
Topic archived. No new replies allowed.