Communication between objects of different class c++ -


How can I validate an object in a different category? Here is an example below that will result in the code screen:

  2 2  

I have to give what I want:

 In other words, I want the object  Bita  (or even the whole class  two ) to accept the object  alpha  And do not create a new object? Is there any way to include object alpha to object object? Please be as simple as I'm starting. 

  #include & lt; Iostream & gt; # Include & lt; Cstdlib & gt; # Include & lt; Cstdio & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; using namespace std; Class A {int A, B; Public: A () {a = 2; } Int func () {back; A; } Zero func2 () {a = 3; }}; Square two {int z, b; Public: Zero Test (); }; Zero two :: exam () {single alpha; Cout & lt; & Lt; Alpha.funk () & lt; & Lt; '\ N'; } Int main () {single alpha; Cout & lt; & Lt; Alpha.funk () & lt; & Lt; '\ N'; Alpha.func2 (); Spend two; Bita.test (); Return 0; }   

A solution will be to pass the object by reference, Code> two :: test this way

  class two {int z, b; Public: Zero Test (A & A); }; Zero two :: Examination (A & A) {cout & lt; & Lt; A.func () & lt; & Lt; '\ N'; }  

and then call it in main

  Bita.test (alpha);  

then the complete code will be

  #include & lt; Iostream & gt; # Include & lt; Cstdlib & gt; # Include & lt; Cstdio & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; using namespace std; Class A {int A, B; Public: A () {a = 2; } Int func () {back; A; } Zero func2 () {a = 3; }}; Square two {int z, b; Public: Zero Test (a & amp;;); }; Zero two :: Examination (A & A) {cout & lt; & Lt; A.func () & lt; & Lt; '\ N'; } Int main () {single alpha; Cout & lt; & Lt; Alpha.funk () & lt; & Lt; '\ N'; Alpha.func2 (); Spend two; Bita.test (alpha); Return 0; }  

Comments