chikucoder
asked on
copy constructor
under what all senario's copy constructor is invoked.hurry up guys
Purpose of copy constructor is to make a new object based on an existing object, where both objects belong to the same class.
another example is
SomeClass B( A ) ;
another example is
SomeClass B( A ) ;
ASKER
how it is different from assignment operator
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. At the time of object creation
2.At datatype casting time
3. At = assignment operator invokation
2.At datatype casting time
3. At = assignment operator invokation
1) MyObject a(myObjectInst);
2) MyObject a = myObjectInst;
3) a = (MyObject)myObjectInst; // if a has been initialised it will call the copy ctor then the assignment op...
// if not then it will call the copy ctor twice,
// once for the cast and once for the initialisation of a.
2) MyObject a = myObjectInst;
3) a = (MyObject)myObjectInst; // if a has been initialised it will call the copy ctor then the assignment op...
// if not then it will call the copy ctor twice,
// once for the cast and once for the initialisation of a.
SomeClass A, B;
A.Assign(); // Assuming you have a method Assign which fills this.
B = A; // Now the copy constructor is invoked