No, you can’t.
For the default value, you can use either a value, a variable, or a function that is available in the context of a function definition that is in the class definition that is outside of any specific context of the object.
This usually helps me think about how the compiler really handles this. In particular, when the compiler performs an overload for a function and detects an overload with more arguments than those used at the call site, the compiler will generate code at the call site to fill in the remaining arguments. The generated code will always generate a call with all arguments:
int g(); void f(int x = g()); int main() { f();
When the compiler processes [1] and has overload permission, it discovers that void ::f(int x = g()) is the best candidate and selects it. Then it fills in the default argument and generates a call for you:
int main() { f( g() ); }
If you consider calling a member function or a member variable of a class, this does not make sense in the context of the caller (the language can be changed to adapt to this, it is impossible to handle this, but it does not work with the current model).
source share