copy constructor

under what all senario's copy constructor is invoked.hurry up guys
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Copy constructor is invoked when you have to assign an instance of the class to another instance of the class. For example in your case,  a sample of the code would be :

SomeClass A, B;

A.Assign(); // Assuming you have a method Assign which fills this.
B = A;        // Now the copy constructor is invoked
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 ) ;
chikucoderAuthor Commented:
how it is different from assignment operator
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

in above example
B = A;  // invoke the assignment operator after invoking the default constructor.


SomeClass B( A ) ;  // invoke the copy constructor
queueClass y = x ;  // invoke the copy too.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
1. At the time of object creation
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.