samedi 23 avril 2016

query about address of object while we are assigning an object to another

i know that when i assign an object to another then they have both same address.but i wanted to visualize that but it is not showing as per my concept.i have had two object t1 and t2 are those object and i am assigning t1 in t2 and according to the concept t1 and t2's address should be same but it is printing different/

#include <bits/stdc++.h>

using namespace std;
class Test
{ public:
int a=1,b=2,c=2;
};


int main()
{
Test t1;
Test t2=t1;
cout<<(&t2)<<endl<<(&t1)<<endl;
cout<<t2.a<<" "<<t1.a<<endl;
t1.a=10;
  cout<<t2.a<<" "<<t1.a<<endl;

}

Aucun commentaire:

Enregistrer un commentaire