dimanche 29 août 2021

making vectors of an object independent of each other

I have a question regarding vectors,shared_ptr, andcopy c'tors in c++

class Character 
{
     int health;//and more stuff that aren't important for the sake of this question
     //more code...
}
class Game 
{
     int size;
     vector<shared_ptr<character>> board;
}

now my question is: When I do :

Game game1 = (53,...)//say that I gave proper values for gaame1 to be constructed.
Game game2 = game1;

what would be the vector that's in game2? meaninng does the vector in game2 have the same address as the vector in game1? or is it a vector with a different address but the same contents?

Moreover: if the answer to my question is that they're the same vector (meaning they have the same address), how can I make them independent of each other? {what I want is for both vectors to have the same contents but different addresses!}

//if anyone is confused by what I mean with contents : it's the shared_ptrs inside the vector

Aucun commentaire:

Enregistrer un commentaire