Hey i have big problem , maybe it's easy to fix but really idk how. I'm creating game and i have one class named TMap. Here i have private vector of SCharacter structures for player info. I need to modify this vector in all other classes (normal for game) so i tried to do vector reference to vector in TMap class something like this in class named TCharacter :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class TMap
{
std::vector<SCharacter> characters;
public:
//constructor and other things here
std::vector<SCharacter>& GetCharacter(){return characters;}
};
class TCharacter
{
const std::shared_ptr<TMap> Map;
std::vector<SCharacter> &characters;
public:
TCharacter(const std::shared_ptr<TMap> Map) : Map(Map),characters(Map->GetCharacter()){}
};
But it isn't working i got errors that characters in TCharacter class cannot be initialized by value . I tried also making vector in TServer class , pass it by reference and initialize it in TCharacter class but it isn't working too.Values aren't the same it's creating new vector gor those classes even if it's reference to othet vector. How i can fix my problem ??