Why are the results different and the problem occurs in the second method?
1) No error.
auto person = getPerson(); // return type : std::unique_ptr<Person>
static_cast<Student*>(person.get())->foo(); // Student inherits Person
2) Segmentation fault before entering the function foo()
auto person = getPerson().get();
static_cast<Student*>(person)->foo();
Aucun commentaire:
Enregistrer un commentaire