In Visual Studio 2008, the following code will build successfully:
void Foo (int x);//Prototype
void Foo(const int x)//Implementation
{
}
However, this will generate an error (unresolved external symbol) during linking:
void Foo (int x);//Prototype
void Foo(const int x)//Implementation
{
}
void Bar()
{
int x = 0;
Foo(x);
}
The problem is because the function implementation for Foo specifies that the integer argument is constant, while the prototype does not require a constant.
Why does this happen? How come the problem isn’t detected during compilation?
It’s because you have a broken compiler. Broken compilers can choose their behavior themselfs. I know some compilers have this broken handling of that case.
Look on MSDN about a manual that documents that broken behavior. It works fine with compliant (non-broken in this regard) compilers.