Page 1 of 1

EE C++ compiler reports an error, but shouldn't

Posted: Sat Oct 15, 2005 9:09 pm
by peterstroeiman
Hi.

I have a piece of code that the EE c++ compiler refuses to compile. I would believe that it is perfectly legit code, and the MS C++ also accepts it. It appears that if I have a base class that has a function that accepts a reference to a class instance, and I call that function from a subclass, it generates a compile error.

I made a simple file, bug.cpp
class A
{
int i;
};

class B
{
protected:
void test(A& a);
};

class C : public B
{
public:
void test();
};

void C::test()
{
A a;
test(a);
}

I compile the file using the command line: ee-g++ -c bug.cpp -o bug.o
The compile returns this output:
bug.cpp: In member function `void C::test()':
bug.cpp(22) : no matching function for call to `C::test(A&)'
bug.cpp(20) : candidates are: void C::test()

If I change the line
test(a);
to
B::test(a);

it compiles fine. But AFAIK, placing the class name where the function is to be found should only be required if there is an ambiguity, but I cannot see any amiguity here.

I'm compiling on a Windows installation using the "PS2Dev Environment for Win32".

Posted: Mon Oct 17, 2005 9:35 am
by radad
This shouldn't compile. C::test effectively hides B::test. This is part of the C++ standard for scope name lookup.

The ambiguity is that the 'test' call in C::test matches the test in the C class scope. Obviously its arguments do not match and therefore doesn;t compile. Class B is in the next scope but it isn't even looked for because a 'test' was found in the first scope.