Friday, 4 April 2014

Is duplicate constructor called when a surrogate returning vigilant is indifferent to another vigilant immediately

i am carrying problem bargain how a cost of this formula comes out like
this:#includeusing namespace std;class three_d{float x,y,z;public:
three_d(){x=y=z=0;cout<<"\n\tDefault Constructor";} three_d(float
a,float b,float c){x=a;y=b;z=c;cout<<"\n\tOverloaded Constructor";}
three_d(const three_d &obj){x=obj.x;y=obj.y;z=obj.z;cout<<"\n\tCopy
Constructor";} three_d operator+(three_d op2); three_d
operator=(three_d op2); vacant show();
~three_d(){cout<<"\n\tDestructor Working !!";}};three_d
three_d::operator+(three_d op2){ x=x+op2.x; y=y+op2.y; z=z+op2.z;
relapse *this; }three_d three_d::operator=(three_d op1){ x=op1.x;
y=op1.y; z=op1.z; relapse *this;}void three_d::show(){
cout<<"\n\n\tValues are : x="<2. Overloaded Constructor3. Default
Constructor4. Copy Constructor5. Copy Constructor6. Destructor Working
!!7. Copy Constructor8. Destructor Working !!9. Destructor Working !!10.
Values are : x=3.1 y=3 and z=3.211. Values are : x=1 y=1 and z=112. Values
are : x=3.1 y=3 and z=3.213. Destructor Working !!14. Destructor Working
!!15. Destructor Working !!So my questions are:In a 5th line of cost what
is this duplicate constructor for? is it for *this pointer (but as it is a
pointer i dont cruise it needs a duplicate constructor)? The fourth line
is for vigilant op2(i suppose) ?If above matter is loyal when overloading
"=" since is wholly one duplicate constructor used(when it also have a
returning value ? When is a temporary(returning) vigilant destructed ?
Please explain how a cost is systematic like this. Even if i change a
overloaded "+" to something like this :three_d three_d::operator+(three_d
op2){three_d temp;temp.x=x+op2.x;temp.y=y+op2.y;temp.z=z+op2.z;return
temp; }the cost of duplicate constructor for "=" stays same(though values
will be changed) i.e wholly 1 duplicate constructor for "=". However we
cruise there contingency be 2 duplicate constructors for "=" 1 for op1
vigilant and other for *this . If i use rudimentary assignment in sure
like : ob3=ob1; a duplicate constructor is called twice as expected.
Please explain.

No comments:

Post a Comment