std::num_get::~num_get(3)
π std::num_get::~num_get β C++ Standard Library realness (that's the manual, bestie, welcome)
Okay so picture this: you're deep in <locale> land, right? And you need to know what happens when a std::num_get facet gets yeeted out of existence. That's literally this whole page. Let's get into it π
β¨ NAME β¨
std::num_get::~num_get β and yes, the name is just the name again, that's how these things go, no notes π
πΈ Synopsis πΈ
So this thing lives up in here:
Defined in header <locale>
and the signature is giving very much protected-and-private-energy:
protected: ~num_get();
What it does: destructs a std::num_get facet. Simple. Iconic. π
Now for the lore β this destructor is protected and virtual (that second part is because the base class destructor is virtual, so it's inherited behavior, iykyk). And because of that protected life, an object of type std::num_get β like most facets, fr fr β can only be destroyed when:
- the last
std::localeobject that implements this facet goes out of scope, or - if a user-defined class is derived from
std::num_getand implements a public destructor.
Lowkey important: you can't just make a std::num_get and destroy it willy-nilly. The destructor being protected means the compiler will absolutely shut you down if you try. It's giving "you don't have access to this floor" energy π«β¨
π¦ Example π¦
Here's the vibe in code β run it if you want:
// Run this code
#include <iostream>
#include <locale>
struct Destructible_num_get : public std::num_get<wchar_t>
{
Destructible_num_get(std::size_t refs = 0) : num_get(refs) {}
// note: the implicit destructor is public
};
int main()
{
Destructible_num_get dc;
// std::num_get<wchar_t> c; // compile error: protected destructor
}
See what she did there? π She derived a class, gave it a constructor that takes std::size_t refs = 0 and forwards it to num_get(refs), and since the implicit destructor of the derived class is public, Destructible_num_get dc; gets to exist and get destroyed like a normal little object. Main character behavior π
But that commented-out line? // std::num_get<wchar_t> c; // compile error: protected destructor β that's the cautionary tale. Try it directly and the compiler says absolutely not. Not me getting rejected by the compiler π
π«Ά Sign-off π«Ά
That's the whole page, bestie β no cap, that's it. Fresh from http://cppreference.com, dated 2024.06.10, and filed under the very fancy manual name C++ Standard Libary (their spelling, not mine, keeping it exactly as it came to me π). Go forth and derive responsibly β¨ππ
π¦ 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