Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Undefined symbols for architecture x86_64:
- "Person::~Person()", referenced from:
- Teacher::~Teacher() in test-9423bf.o
- Student::~Student() in test-9423bf.o
- ld: symbol(s) not found for architecture x86_64
- #include <iostream>
- #include <vector>
- #include <memory>
- class Person {
- public:
- virtual void printName() = 0;
- virtual ~Person() = 0;
- };
- class Teacher : public Person {
- public:
- void printName() {
- std::cout << "Hello My Name is Teacher" << std::endl;
- }
- ~Teacher() {}
- };
- class Student : public Person {
- public:
- void printName() {
- std::cout << "Hello My Name Is Student" << std::endl;
- }
- ~Student() {}
- };
- //Capturing the raw pointer and letting it go out of scope
- template<typename Person, typename Teacher>
- std::unique_ptr<Person> static_unique_pointer_cast (std::unique_ptr<Teacher>&& old){
- return std::unique_ptr<Person>{static_cast<Person*>(old.release())};
- //conversion: unique_ptr<FROM>->FROM*->TO*->unique_ptr<TO>
- }
- auto main() -> int {
- auto t1 = std::make_unique<Teacher>();
- auto t2 = std::make_unique<Teacher>();
- auto t3 = std::make_unique<Teacher>();
- auto s1 = std::make_unique<Student>();
- auto s2 = std::make_unique<Student>();
- auto s3 = std::make_unique<Student>();
- std::vector<std::unique_ptr<Person>> v;
- // v.push_back(static_unique_pointer_cast<Person>(std::move(s1)));
- auto foo = static_unique_pointer_cast<Person>(std::move(s1));
- // std::vector<std::unique_ptr<Person>> ve = {
- // std::move(t1),
- // std::move(t2),
- // std::move(t3),
- // std::move(s1),
- // std::move(s2),
- // std::move(s3)
- // };
- return 0;
- }
Add Comment
Please, Sign In to add comment