 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
peterstroeiman
Joined: 16 Sep 2005 Posts: 11
|
Posted: Sat Oct 15, 2005 9:09 pm Post subject: EE C++ compiler reports an error, but shouldn't |
|
|
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". |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Mon Oct 17, 2005 9:35 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|