[讨论]关于memberwise和bitwise
一直有个疑问:拷贝时,memberwise和bitwise有何区别。
今天看了英文版<inside the c++ object model>,第59页最后和第60页开头,有这么句话:There are no member or base class objects with a copy constructor that need to be invoked. Nor is there a virtual base class or virtual function associated with the class. So, by default, a memberwise initialization of one Point3d class object with another result in a bitwise copy.
class Point3d{
public:
Point3d(float x, float y, float z);
//...
private:
float _x, _y, _z;
};
我的理解是,拷贝构造函数的目的就是为了实现按成员初始化(memberwise initialization),在除了上面所说的四种情况外,可以通过按位拷贝(bitwise copy)来实现。