By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

Communication between objects

P: 3
Hello,
I was wondering how it could be posslible for one object to call methods of another object. I mean: there is some object instantiated. Now we create some new different object and give him pointer to the first object. Over this pointer within the second object we can call methods of first object.

Please could you paste some examples how this could be done?

regards
-oneshed-
Aug 5 '07 #1
Share this Question
Share on Google+
1 Reply


ilikepython
Expert 100+
P: 844
Hello,
I was wondering how it could be posslible for one object to call methods of another object. I mean: there is some object instantiated. Now we create some new different object and give him pointer to the first object. Over this pointer within the second object we can call methods of first object.

Please could you paste some examples how this could be done?

regards
-oneshed-
Is this what you mean?:
Expand|Select|Wrap|Line Numbers
  1. class objA
  2. {
  3.     public:
  4.         void reply() { cout << "objA's reply!" << endl; };
  5. };
  6.  
  7. class objB
  8. {
  9.     public:
  10.         void callreply() { cout << "objB's method" << endl;
  11.                                obja->reply(); };
  12.     private:
  13.         objA *obja;
  14. };
  15.  
  16. int main()
  17. {
  18.     objB myObj;
  19.     myObj.callreply();
  20.  
  21.     return 0;
  22. }
  23.  
Aug 5 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.