Guest User

Untitled

a guest
Feb 15th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. Undefined symbols for architecture x86_64:
  2. "Person::~Person()", referenced from:
  3. Teacher::~Teacher() in test-9423bf.o
  4. Student::~Student() in test-9423bf.o
  5. ld: symbol(s) not found for architecture x86_64
  6.  
  7. #include <iostream>
  8. #include <vector>
  9. #include <memory>
  10.  
  11. class Person {
  12. public:
  13. virtual void printName() = 0;
  14. virtual ~Person() = 0;
  15. };
  16.  
  17. class Teacher : public Person {
  18. public:
  19. void printName() {
  20. std::cout << "Hello My Name is Teacher" << std::endl;
  21. }
  22. ~Teacher() {}
  23.  
  24. };
  25.  
  26. class Student : public Person {
  27. public:
  28. void printName() {
  29. std::cout << "Hello My Name Is Student" << std::endl;
  30. }
  31.  
  32. ~Student() {}
  33.  
  34. };
  35.  
  36. //Capturing the raw pointer and letting it go out of scope
  37. template<typename Person, typename Teacher>
  38. std::unique_ptr<Person> static_unique_pointer_cast (std::unique_ptr<Teacher>&& old){
  39. return std::unique_ptr<Person>{static_cast<Person*>(old.release())};
  40. //conversion: unique_ptr<FROM>->FROM*->TO*->unique_ptr<TO>
  41. }
  42.  
  43. auto main() -> int {
  44.  
  45.  
  46. auto t1 = std::make_unique<Teacher>();
  47. auto t2 = std::make_unique<Teacher>();
  48. auto t3 = std::make_unique<Teacher>();
  49.  
  50. auto s1 = std::make_unique<Student>();
  51. auto s2 = std::make_unique<Student>();
  52. auto s3 = std::make_unique<Student>();
  53.  
  54. std::vector<std::unique_ptr<Person>> v;
  55. // v.push_back(static_unique_pointer_cast<Person>(std::move(s1)));
  56.  
  57. auto foo = static_unique_pointer_cast<Person>(std::move(s1));
  58. // std::vector<std::unique_ptr<Person>> ve = {
  59. // std::move(t1),
  60. // std::move(t2),
  61. // std::move(t3),
  62. // std::move(s1),
  63. // std::move(s2),
  64. // std::move(s3)
  65. // };
  66.  
  67. return 0;
  68. }
Add Comment
Please, Sign In to add comment