so I have something that looks a bit like this:
class A
{
public:
A();
virtual void yep();
private:
};
A::A()
{
}
void A::yep()
{
std::cout << "A" << std::endl;
}
class B : public A
{
public:
B();
void yep() override;
private:
};
B::B() : A()
{
}
void B::yep()
{
std::cout << "B" << std::endl;
}
int main() {
std::vector<A> d;
A a = A();
A b = B();
A& c = b;
d.push_back(a);
d.push_back(c);
//for each
for (A i : d) {
A& j = i;
j.yep();
}
}
I'm expecting it to produce an output AB but instead, but I'm getting AA instead. Stepping through it lines by line in my code editor says it's executing the function of the superclass instead of the overridden one. Edit: So the thing with pointer/reference works and I've tried applying it to my implementation but it doesn't work. I've modified the example to look more like my implementation.