I saw this in a textbook, but the book doesn’t explain what it actually does, and why I should do this. Here is something similar to the example in the book:
class MyClass
{
public:
MyClass(int initial_capacity = 20);
private:
int capacity;
}
I can’t use initial_capacity in the implementation, I can’t even implement anything, so I am confused as to what this is for? Does it set capacity to 20 somehow? How is this a default constructor?
Probably, there is missed implementation of constructor. For example, if constructor looks like this one :
If you create object this way:
capacity will be set to 10.
On the other hand, if you will create object like this:
capacity will be set to 20.