I wonder if i could store different types of non-native data into a single vector? it goes like this:
class foo
{
private:
int x;
public:
foo(int a=0):x(a){}
int getx() { return x; }
void setx(int a=0) { x=a; }
};
class var:public foo
{
private:
int y;
public:
var(int a=0, int b=0):foo(a), y(b){}
int gety() { return y; }
void sety(int a=0) { y=a; }
};
class var1:public foo
{
private:
int z;
public:
var(int a=0, int b=0):foo(a), z(b){}
int getz() { return z; }
void setz(int a=0) { z=a; }
};
How to declare a vector to hold data of both var
and var1
types?
I could store them in a std::vector<foo>
, but then they'd be treated as if they are of foo
types