I have the following classes:
class Vertex {
public: float X;
float Y;
float Z;
Vertex (float first, float second, float third){
X=first;
Y=second;
Z=third;
}
};
class Obj {
vector<Vertex>vertexCoordinates;
vector<vector<int>> faces;
vector <vector<float>> faceNormals;
vector <vector<float>> faceCenters;
string objName;
int vertexCount, faceCount, edgeCount;
float maxX, minX, maxY, minY, maxZ, minZ, dx, dy, dz;
setVertexCoordinates(vector <Vertex> vertexCoordinatesP) {
vertexCoordinates = vertexCoordinatesP; //??
// How should the assignment be defined?
}
};
Do I need to create a copy constructor here? Overload the operator =
for Vertex
and Obj
?
Since your Vertex
has only primitive non-pointer members, you don't necessarily need to define a copy constructor for it: the compiler will generate one for you that copies the elements by their copy constructors (in the case of a float
, that's usually a bitwise copy). The copy constructor and assignment operator for std::vector
are predefined and will work here because you are not storing pointers.
(For an std::vector<Vertex *>
, the ownership semantics would not be clear so you might need to copy in a different way.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With