Last active
April 19, 2018 13:33
-
-
Save nomaddo/a2105de5752d6f2481d1c8a73a7fca12 to your computer and use it in GitHub Desktop.
これはどうすればいいの、、、、
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
// ^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment