I have checked Stack Overflow for a sample of these class vectors and none of the answers point out common uses of vectors in a class . My code works but I have a few questions on it .
I have a struck of objects that is stored in a class member vector
struct Station
{
std::string StationName;
int StationId;
int PlayerId;
std::vector<float> position;
};
Here is the class that declaration with the Vectors
class playerData
{
public:
std::vector <playerDataDetails> PlayerList;
std::vector<Station> Stations;
void addNewPlayer(std::string Name , std::string faction , int Id );
void PrintPlayer();
void AddStations(int PlayerNumber, std::string name);
};
When running the member function this is how Im accessing the Vector
void playerData::AddStations(int PlayerNumber, std::string name)
{
// p[i].
Station s ;
s.StationName = name;
s.StationId = 1;
s.PlayerId = PlayerNumber;
s.position = { 2.1f, 1.1f , 1.1f};
// s.position = { { 2.1f }, { 2.3f }, { 2.3f } };
this->Stations.push_back(s);
}
My question is this .
this->Stations.push_back(s);
- Is this the correct way to add station to the stations vector ?
- Is this copy or move Semantics ?
- Is there another way of doing this with pointers and references ?
- And is this the most efficient way of working with Vectors in a class ?