Mostly when someone is coding in C, but there are some occasions where a
structure is used only once, for a very specific purpose, within a function
scope, and it serves no point to declare the structure formally. Such as,
using an example from real C++ code, and not a contrived example from a
garbage C++ book:
static const struct {
const char *name;
font &(font::*handler)(double);
} double_values[]={
{ "point_size", &font::set_point_size},
{ "scaled_size", &font::set_scaled_size},
{ "scale", &font::scale},
};
for (const auto &v:double_values)
{
// ...
Need a mapping between symbolic labels and class methods here. Simply
declare an anonymous struct and iterate over it, doing what needs to be done.
No need to formally declare this, in some header file, somewhere, when this
is needed just here and nowhere else.
P.S., it's not a "tag", but a class name. Given the other garbage example
you showed from this so-called "C++ book", you might consider returning it
for a refund and getting a better C++ book to learn from. C++ is hard enough
as it is.