where I assumed the 'C' in '<C>' was a placeholder.... |
I'm not sure what you mean by "placeholder" here.
C is the type used to create the actual class from the template. Do you understand what templates are, and how they work?
In the code you've posted, the type
C is being used as the first template parameter for
basic_string, which is called
CharT in that cppreference page, yes.
Ok, so what is line 4, and why is is not marked '= default' ? I mean, isn't this the default constructor? |
You've either not read, or not understood, the page I linked you to. You're muddling up two different uses of the word "default".
1)
Default constructor means the constructor that takes no arguments. So, yes, line 4 defines the default constructor.
2) There are certain members of a class that, if we do not define them explicitly, the compiler can automatically generate them. These include:
- the
default constructor
- the
copy constructor
- the
move constructor
- assignment operators.
There are rules about how and when the compiler does this, but declaring these members using
= default
makes it explicit that we want the compiler to generate these automatically.
Crucially, as you can see, on line 4 the default constructor is being explicitly defined for this class - clearly, we are not wanting the compiler to automatically generate one.
Also, if '= default' were left off of lines 6 and 7, then what would that do to this definition? |
It would cause
compilation linking to fail, because you've declared that you're going to define these members, but supplied no actual definitions of them.
EDIT: I've used "class" all the way through, when your code actually declares a struct. Since classes and structs are almost identical except for one obvious detail, everything I've said still applies to structs.