Q:

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() before main(), it gives no error.  What is going on?  Please help.  Thank you.

A:

This error is because you have optional variables when you call your function, but not in your declaration. 
This will create a function with two variables:
void myFunction(string something, int w);

However, this would make the second variable optional:
void myFunction(string something, int w=5);

You need to make the declaration have a optional variable.
Also, I am surprised your compiler didn't try to spit some sort of error relating to a redefinition. (That might even be a compiler bug! I will update on research into this. Update: Doesn't seem like compiler bug, but definitely a feature I would love to have. Even if it was a bug, it would be linker related.)

