I know there's virtual functions, but no virtual variables. It wasn't added probably because it wasn't needed most of the time, but I've ran into a problem lately:
class A
{
public:
int bar;
};
class B : public A
{
public:
float foo;
};
class C : public A
{
public:
double foo;
};
int main()
{
std::vector<A*> v;
v.push_back(new B());
v.push_back(new C());
std::cout << v[1]->bar << v[0]->foo; //error because it will not find 'foo' in A
}
Is there anyway that I can stop this error?