c++ - Why does passing an object by value work even if that object has no copy constructor? -


according this question copy constructor called when object passed value function.

i removed copy constructor test can still pass value. make sense?

i commented out copy constructor:

 /* matrix4(const matrix4<t>& m) {     x.x = m.x.x; x.y = m.x.y; x.z = m.x.z; x.w = m.x.w;     y.x = m.y.x; y.y = m.y.y; y.z = m.y.z; y.w = m.y.w;     z.x = m.z.x; z.y = m.z.y; z.z = m.z.z; z.w = m.z.w;     w.x = m.w.x; w.y = m.w.y; w.z = m.w.z; w.w = m.w.w; }  */  typedef matrix4<float> mat4; 

then compiles , runs fine:

void ttt(mat4 hi){  }  void yyy(){     mat4 x;     ttt(x); } 

so perhaps copy constructor not called in such case? happening here?

if don't provide copy constructor, compiler generates 1 you, gets used when pass value (in c++11 there possibility move copy constructor gets called in circumstances.) disable it, should declare private, or delete in c++11:

class foo {  private:   foo(const foo&); };  class foo11 {  public:   foo(const foo&) = delete; }; 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -