I have a class:
class Geometry{
std::vector<Subset *> subsets;
int verticesCount;
...
};
I want to add a copy constructor, so I can make a deep copy of that object (with own subsets
, NOT only own pointers to same subsets
).
I have tried this:
Geometry & Geometry::operator=(const Geometry &other){
verticesCount = other.verticesCount;
Subset * subset = 0;
for(unsigned int i=0; i<other.subsets.size(); i++){
subset = new Subset();
subsets.push_back(subset);
}
...
return *this;
}
The problem is Subset
has none default constructor, so I get error at subset = new Subset()
.
I also have more members that don't have default constructors.
How to solve that problem?
I would prefer NOT to add default constructors for all that members (Subset
etc.) The best solution would be NOT to change member classes at all (Subset
etc.), but I can add something to them, if it's necessary.
They don't have default constructors for reasons, e.g. security (I don't want to let somebody create a Model3D
class without giving filename (so the vertex buffers can be created and I can assume that all Model3D
objects has not-empty filename associated).
edit:
Because of comment. Subset
is an example of member class without default constructor.
In that case it's my own class:
class Subset{
...
public:
Subset(bool useLineTopology, int vertexIndexStart, int vertexIndexAmmount = -1);
...
};
But I also have many others members without default constructor, like DirectX's ID3D11Buffer * constantBuffer
.