I’m trying to figure out the difference between these two lines of code..
We are given ‘Count’ is our Class name, C1 and C2 are objects of that class. No information of how and when the classes have been declared are given.
Count C2(C1); //Statement 1
Count C2=C1; //Statement 2
No other information is given. What is the difference between these two lines of call for copy constructor? Please elaborate if you have the answer.
Thanks!
At the grammatical level, the first one is called “direct initialization” and the second one is called “copy initalization”. If
Countis of class type (i.e. not a typedef ofint, say), then both versions, equivalently, cause the copy constructor to be called.The first version works in any case, the second version does not work if the copy constructor is declared
explicit.