Why copy constructor and assignment operator are disallowed?

后端 未结 3 1235
面向向阳花
面向向阳花 2020-12-19 07:07
#undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)    \\
   TypeName(const TypeName&);                           \\
            


        
3条回答
  •  萌比男神i
    2020-12-19 07:26

    If your type contains pointer or reference members, or it makes no semantic sense for it to be copied (e.g. it has a resource handle that must be freed in the destructor) then it is good practice to disable the copy constructor and assignment operator. In C++0x (e.g. in g++ 4.4 or later in -std=c++0x mode) you can declare them deleted. In older compilers you just declare them private and unimplemented.

提交回复
热议问题