In a C++ function, can I use one of the parameter’s getter to set the default value of the other parameter following it? For example if I have the followig class Foo,
class Foo{
public:
setID();
getID();
private:
string id;
}
Can I write a function fooManipulator like this,
int fooManipulator(Foo bar, string id = bar.getId());
No, as has been stated, the order of evaluation of arguments to a function is unspecified.
However, you can achieve the effect easily with an overload like this: