Skip to content

Instantly share code, notes, and snippets.

View wenjinghuan999's full-sized avatar

wensir wenjinghuan999

View GitHub Profile
@wenjinghuan999
wenjinghuan999 / shared_from_this_passkey_idiom.cpp
Created October 18, 2022 09:17
Use passkey idiom when you want enable_shared_from_this to use make_shared
#include <memory>
class A : public std::enable_shared_from_this<A> {
private:
struct key{ explicit key() = default; };
public:
static std::shared_ptr<A> create() {
return std::make_shared<A>(key{});
}
explicit A(key) {}