The essence of what you are asking can be redone into this simple example.
void foo(int a, int b = a);
This is not allowed in C ++. C ++ does not allow default arguments to depend on other parameters.
Using class members as default arguments is only a special case of the above, since classes are accessed using the this pointer, and the this pointer is another hidden parameter of each non-static member function.
So the question is why
void foo(int a, int b = a);
is not allowed.
One obvious potential reason for rejecting this is that it will impose additional requirements on the order in which arguments are evaluated. As you know, in C ++ the order of evaluating the function argument is not specified - the compiler can evaluate the arguments in any order. However, in order to support the aforementioned default argument functionality, the compiler had to make sure that a evaluates to b . This seems like an excessive requirement that limits the typical freedom of evaluation order that we are used to seeing in C ++.
Please note that this
int a; void foo(int b = a);
allowed in C ++. And, obviously, it does not demonstrate the above assessment procedure.
source share