daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Apr 26th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. //  ^
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top