The following code is correct and simple
Now what if I want give bool& and string& a default value so that someone can call foo() and foo2() without parametersCode:void foo(bool& valid) { valid = true; return; } void foo2(string& str) { str = "abc"; return; } void main() { bool valid; foo(valid); string str; foo2(str); return; }
Why it doesn't work?Code:void foo(bool& valid = bool(true) ) { valid = true; return; } void foo2(string& str=string("")) { str = "abc"; return; } void main() { bool valid; foo(); foo2(); return; }