Testing polymorphism & virtual functions & shared_ptr, I am trying to understand the situation described by the following minimal example.
class B{
public:
// Definition of class B
virtual void someBMethod(){
// Make a burger
};
};
class C : public B {
public:
// Definition of class C
void someBMethod(){
// Make a pizza
};
};
class A{
public:
A(B& SomeB) : Member(std::make_shared<B>(SomeB)){};
std::shared_ptr<B> Member;
};
Now, in the main we can have
int main(){
C SomeC;
A SomeA(SomeC);
A.Member->someBMethod(); // someBMethod from B is being executed.
};
Unless I didn't include some mistake from my actual code to the minimal example, I think SomeC is getting sliced down to a B, or at least someBMethod from B is being calledin the last line.
Question: What should be the right way to initialize Member in such a way that the method someBMethod from C gets called?