Testing polymorphism and virtual functions and shared_ptr, I am trying to understand the situation described in the following minimal example.
class B{
public:
virtual void someBMethod(){
};
};
class C : public B {
public:
void someBMethod(){
};
};
class A{
public:
A(B& SomeB) : Member(std::make_shared<B>(SomeB)){};
std::shared_ptr<B> Member;
};
Now, basically, we can have
int main(){
C SomeC;
A SomeA(SomeC);
A.Member->someBMethod();
};
If I had not included some error from my actual code in a minimal example, I think that it SomeCis sliced ββto B, or at least someBMethodfrom, Bcalled in the last line.
Question: What should be the correct way to initialize Memberso that the called method someBMethodfrom is Ccalled?
source
share