I want to share the same vector between derived classes and access the string as individuals. I get an error with unresolved externals. What is going wrong. Is there any other way of sharing a vector between classes without static methods.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class base
{
public:
static vector<string> v1;
void set(string val);
vector<string> getval();
};
void base::set(string val)
{
v1.push_back(val);
}
vector<string> base::getval()
{
return v1;
}
class derived :public base
{
public:
void vec();
};
void derived::vec()
{
string b = "sfd";
derived d;
d.set(b);
}
class derive2:public base
{
public:
void vec2();
};
void derive2::vec2()
{
derive2 f;
vector<string> a(100);
a = f.getval();
}
int main()
{
derived a;
a.vec();
derive2 b;
b.vec2();
a.vec();
b.vec2();
return 0;
}
How to get the vector in a derived class