How are C++ array members handled in copy control functions?
This is something I have wondered for a long time. Take the following example:
struct matrix
{
float data[16];
};
I know what the default constructor and destructor do in this specific example (nothing), but what about the copy constructor and the copy assignment operator?
struct matrix
{
float data[16];
// automatically generated copy constructor
matrix(const matrix& that) : // What happens here?
{
// (or here?)
}
// automatically generated copy assignment operator
matrix& operator=(const matrix& that)
{
// What happens here?
return *this;
}
};
Does it involve std::copy
or std::uninitialized_copy
or memcpy
or memmove
or what?
This is what the standard says in 12.8 (Copying class objects). Copy construction:
Each subobject is copied in the manner appropriate to its type:
Copy assignment:
Each subobject is assigned in the manner appropriate to its type:
上一篇: 获取指向数组末尾的指针