Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <memory>
- class A : public std::enable_shared_from_this<A> {
- public:
- int id;
- A(int x) : id(x) {}
- };
- class B : public A
- {
- public:
- B() : id(1000);
- };
- int main() {
- A a(100);
- a.shared_from_this();
- B b;
- std::shared_ptr<B> bad = b.shared_from_this();
- }
- //
- // /home/nomaddo/CLionProjects/test/main.cpp: In function ‘int main()’:
- // /home/nomaddo/CLionProjects/test/main.cpp:20:29: error: conversion from ‘std::shared_ptr<A>’ to non-scalar type ‘B’ requested
- // B bad = b.shared_from_this();
- // ^
Add Comment
Please, Sign In to add comment