Let's say I have a base class and two derived classes:
class a {};
class b : a { int a; };
class c : a { int b; };
And I have a list of the base class, and I insert the derived class into the list:
std::list<a> list;
list.emplace_back(b());
list.emplace_back(c());
Now, I want to access int a
like this:
for(auto i : list)
{
i.a = 5;
}
I already have checks in place to see what class it is, but the compiler is still not letting me access it.
How can I access any field in the derived class from the base class?
This question has been asked many times, but none of the methods have worked for me so far.