If it Foo
can be inferred from, consider what happens when you have a class Bar
derived from Foo
, and copy-construct a Foo
from this instance Bar
.
- , sizeof(Foo)
, ( vtable), .
, Bar
Foo
, : Foo
. memcpy
.
:
, , - string
vector<>
, , .
? , .
, . , , , :
class Foo
{
public:
Foo(const Foo& from)
{
m_Data = from.m_Data;
m_Data.m_someData = new int[m_Data.m_dataLength];
memcpy(m_Data.m_someData, from.m_Data.m_someData, m_Data.m_dataLength * sizeof(int));
}
private:
struct Data {
int* m_someData;
int m_dataLength;
};
Data m_Data;
};
, m_Data = from.m_Data;
, memcpy
, , .