I have the following Code:
class Base {
public:
virtual std::string name() {
return "Base";
}
};
class B : public Base {
public:
virtual std::string name() {
return "B";
}
};
class A : public Base {
public:
Base base;
A(Base &base) : base(base) {
std::cout << base.name() << "\n";
}
};
int main() {
Base a = B();
Base r = A(a);
}
The output is "Base", what do I have to change to get the Output "B" and why?