COPY CONSTRUCTOR(sololearn misses it)
WELL IT SEEMS THAT SOLOLEARN MISSES SOME OF THE TOPICS HERE IS ONE OF THE TOPICS EXPLAINED. COPY CONSTRUCTOR A copy constructor copies value of one object to other object. Let there be a class as class abc { int a,b; public: void somefunctions(); int c,d; //NOW THE COPY CONSTRUCTOR abc(abc &ob) { a=ob.a; b=ob.b; c=ob.c; d=ob.d; } }ob1; There are three situations when a copy constructor is called. 1.abc ob2=ob1;(object defined and initialized with another object. 2.When an object is passwd by value to a function. 3.When a function returns an object. When we do not define a copy constructor the compiler creates an implicitly-defined copy constructor which is inline public member of its class. Also ob1=ob2; does not calls copy constructor. It simply assigns values of ob2 data members to ob1 data members. IMPORTANTLY copy constructor has syntax <classname>(<classname>&) This is so because if objects are passed by value then the object needs to be copied to the temporary function object. And to copy object copy constructor works itself. So it calls itself recursively until compiler complains out of memory. Well check a real code. https://code.sololearn.com/cf9IjrUkhyzy/#cpp Well if you really read it all then reply how can you stop objects prom being copied.