I'm confused by this situation and googling didn't give me the answer. Basically I have the following simple code that doesn't compile:
#include <iostream>
class A
{
public:
int a(int c = 0) { return 1; }
static int a() { return 2; }
};
int main()
{
std::cout << A::a() << std::endl;
return 0;
}
In compiling this, GCC 4.2 says the call to A::a()
in main()
is ambiguous with both versions of a()
valid candidates. Apple's LLVM compiler 3.0 compiles with no error.
Why is gcc confused about which function I want to call? I thought it was obvious that by qualifying a()
with A::
I'm asking for the static
version of the function. Naturally this code still doesn't compile if I remove the static
function a()
, because A::a()
is not valid syntax for calling the non-static
a()
.
Thanks for any comment!