Hi, lets say i have

class Players{
public: vector <strings> info

and class that inherits from it

class son:public Players{


now in the main function i make 2 of those so now i have 2 vectors in memory
that vector holds the same data for all of the sons i create
so is there a simple way to make them share that info?

something like static? thanks

6 Years
Discussion Span
Last Post by Ancient Dragon

make the vector static.

class Players{
public: static vector <strings> info

Then in one of the *.cpp files declare it again as if it were a global variable

// Players.cpp
#include "Players.h"

Players::vector<string> info;

Edited by Ancient Dragon: n/a

Votes + Comments
Direct / wise

yeah i said like static cuz i wasnt sure it works
i get

error LNK2001: unresolved external symbol

any solution?
my player has a c-tor that uses the static.
and its a virtual class


Depends on what the external symbol was. Did you see the second part of my answer, or does that error refer to something else (the error message should have told you the name of the symbol)?

Edited by Ancient Dragon: n/a


well , just saw the edit and i tried adding that line

Players::vector <string> info;

but i get "info is not a member of players"
so i tried just writing


it worked but i still get ex-symbol problems
kinda long ... no idea why
(moveable = player)

1>Moveable.obj : error LNK2001: unresolved external symbol "protected: static class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > Moveable::_blockers" (?_blockers@Moveable@@1V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@A)

ty for trying

Edited by Despairy: n/a


Thanks! fixed!
so now all sons have the same info list right?
so if in son #1 i add another information everyone will get it?
thanks again


You are right. You might have to synchronize access to info if you have a multi-threaded program and two or more threads try to access info at the same time. You don't have to worry about that if your program has only one thread.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.