C++ messed up: optional argument forced to be mandatory
问题 I want to have a function with optional argument. However, VC++ is throwing an error I cannot comprehend. The code is as simple as follows: #include <iostream> #include <iomanip> #include <string> using namespace std; void myFunction(string something, int w); int main() { myFunction("a string"); int a = 1; } void myFunction(string something, int w = 5) { cout << something << " - " << w << endl; } It complains: 'myFunction': function does not take 1 arguments However if I move myFunction()