Guest User

Untitled

a guest
Apr 26th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <memory>
  2.  
  3. class A : public std::enable_shared_from_this<A> {
  4. public:
  5. int id;
  6. A(int x) : id(x) {}
  7. };
  8.  
  9. class B : public A
  10. {
  11. public:
  12. B() : id(1000);
  13. };
  14.  
  15.  
  16. int main() {
  17. A a(100);
  18. a.shared_from_this();
  19. B b;
  20. std::shared_ptr<B> bad = b.shared_from_this();
  21. }
  22.  
  23. //
  24. // /home/nomaddo/CLionProjects/test/main.cpp: In function ‘int main()’:
  25. // /home/nomaddo/CLionProjects/test/main.cpp:20:29: error: conversion from ‘std::shared_ptr<A>’ to non-scalar type ‘B’ requested
  26. // B bad = b.shared_from_this();
  27. // ^
Add Comment
Please, Sign In to add comment