C++ Constructor call -


I have written this small code snippet in C ++, the output is also attached, I can not understand that the constructor Why is it being called only once, while I can prepare two calls for the district.

From what I think, the default constructor and overloaded assignment operator should be called on Line 28.

Can someone put some light on it:

  1 #include & lt; Iostream & gt; 2 namespace css; 3 4 squares ABC (5 four C; 6 public: 7 ABC (8) COAT & lt; "default" & lt; endl; 9} 10 ABC (four c) {11-> C = C; 12 cout  

  Output to G ++ version 4.0.1: ~ / src $ g ++ test.cpp ~ / src $ ./a.out b 0x bffff0ee destructors B 0xbffff0ef defeating    

The code you call the copy constructor, this definition is:

  ABC (Const ABC & e): C (AC) {Sioatti & lt; & lt; "copy" & lt; & lt; hex & lt; & lt; & Amp; a & lt; & lt; endl;}  

and you see output like this:

  b copying 0x7fffebc0e02f 0x7fffebc0e02e Killer B 0x7fffebc0e02f Killer B  

If you want to call the default constructor and the assignment op Etr you have to use two separate statements:

  ABC B ( 'B'); ABC A; A = B;  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -