Setter function for vector <someClass> in C ++

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 Vertexand Obj?

+5
source share
4 answers

Vertex , , : , ( float, ). std::vector , .

( std::vector<Vertex *> , -.)

+3

, , . , . , , .

+1

, , , , -\ .

0

, , POD, :

struct Vertex { float x; float y; float z; };

, :

inline Vertex mk_Vertex (float x, float y, float z) {
  Vertex a; a.x = x; a.y=y; a.z=z; return a; }

inline Vertex mk_Planar (float x, float y) {
  Vertex a; a.x=y; a.y=y; a.z=0.0f; }

This gives you a few named constructors and leaves Vertex a POD, which means you can also use C-style initializers:

Vertex a = {1.0f, 2.0r, 3.0f };

which can be very useful for higher order aggregates, such as arrays, or for displaying images on and off the disk.

0
source

All Articles