std::enable...ed_from_this(3)
π NAME π
hey bestie π this is the std::enable...ed_from_this(3) page, and it lives in the C++ Standard Libary manpage set (yes, "Libary" is what the header says β we're keeping the typo, it's iconic π
).
std::enable_shared_from_this::enable_shared_from_this - std::enable_shared_from_this::enable_shared_from_this
periodt. that's the constructor-page full name, and the NAME line is literally that same path twice with a dash between them. π
β¨ Synopsis β¨
okay so there are two constructor overloads in the synopsis, and both are tagged (since C++11). here's the synopsis verbatim, because bestie we do not mess with signatures:
constexpr enable_shared_from_this() noexcept;
(1) (since C++11)
enable_shared_from_this( const enable_shared_from_this& other )
(2) (since C++11)
noexcept;
The description is simple: it constructs a new enable_shared_from_this object. The exposition-only std::weak_ptr<T> member weak-this is value-initialized. That's it, that's the construction lore. β¨
π«Ά Parameters π«Ά
otherβ anenable_shared_from_thisto copy. (the one and only parameter, bestie π«Ά)
π Notes π
there is no move constructor: moving from an object derived from enable_shared_from_this does not transfer its shared identity. so don't expect the shared identity to come with you when you move β it literally does not. π
π Example π
this example is giving main character energy. run it if you want:
// Run this code
#include <memory>
struct Foo : public std::enable_shared_from_this<Foo>
{
Foo() {} // implicitly calls enable_shared_from_this constructor
std::shared_ptr<Foo> getFoo() { return shared_from_this(); }
};
int main()
{
std::shared_ptr<Foo> pf1(new Foo);
auto pf2 = pf1->getFoo(); // shares ownership of object with pf1
}
π See also π
shared_ptrβ smart pointer with shared object ownership semantics(C++11)(class template). iykyk
that's the whole page, bestie π«Ά source: http://cppreference.com Β· date: 2024.06.10 Β· page: std::enable...ed_from_this(3).
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms