You can write it like this without a typedef:
struct Region { bool hasPoly; long size1; long size2; long size3; long size4; long size5; long size6; long meshRef; std::vector<int> PVS; };
To answer your questions:
Is the vector in this ad valid
Yes it is.
or it makes sense to do a pointer to a vector.
No, probably not. If you did, you would have to implement a copy constructor, an assignment operator, and a destructor for copy behavior. In the end, you will have the same thing, but it will be additional work and could potentially lead to errors.
In the case of a pointer to a vector, I need to select a new vector. How to do it?
You will need to implement the copy constructor, copy assignment operator, and destructor:
// Copy constructor Region(const Region & rhs) : hasPoly(rhs.hasPoly), // ... copy other members just like hasPoly above, except for PVS below: PVS(new std::vector<int>(*rhs.PVS)) { } // Copy assignment operator Region & operator=(const Region & rhs) { if (this != &rhs) { hasPoly = rhs.hasPoly; // ... copy all fields like hasPoly above, except for PVS below: delete PVS; PVS = new std::vector<int>(*rhs.PVS); } return *this; } // Destructor Region::~Region() { delete PVS; }
Bottom line: your code is fine. You do not need to change it.
EDIT: Commit the assignment operator: check the comparison with this and return * this.
source share