std::money_get::~money_get(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

std::money_get::~money_get β€” std::money_get::~money_get

okay so this page is std::money_get::~money_get(3), and it lives in the C++ Standard Libary manual (yep, that spelling is in the header, bestie β€” we are not touching it πŸ’…). It's giving β€œtiny destructor page with serious access-control energy.” πŸŽ€


✨ Synopsis ✨

  • Defined in header <locale>
protected: ~money_get();

This destructor is protected and virtual β€” the virtual part is due to base class destructor being virtual, iykyk. It destructs a std::money_get facet 🧚.

So here's the vibe: an object of type std::money_get, like most facets, can only be destroyed when the last std::locale object that implements this facet goes out of scope β€” or if a user-defined class is derived from std::money_get and implements a public destructor. That's the whole rule, fr fr. 🫢


πŸŽ€ Example πŸŽ€

Run this code, bestie:

// Run this code

#include <iostream>
#include <locale>

struct Destructible_money_get : public std::money_get<wchar_t>
{
    Destructible_money_get(std::size_t refs = 0) : money_get(refs) {}
    // note: the implicit destructor is public
};

int main()
{
    Destructible_money_get dc;
    // std::money_get<wchar_t> c; // compile error: protected destructor
}

Not me leaving that // compile error: protected destructor comment right there πŸ’€ It's literally the plot twist: protected destructor says β€œbestie, no πŸ’….”


that's the whole vibe β€” signing off from http://cppreference.com, version 2024.06.10, on this very std::money_get::~money_get(3) page 🫢✨🌈

πŸ“¦ where this page comes from