User forums > General (but related to Code::Blocks)
do I understand C++ wrong?
MoonKid:
It is a simple problem.
The compiler (mingw32) says
[error]
main.cpp:27: error: no matching function for call to `ClassB::Function()'
main.cpp:17: note: candidates are: bool ClassB::Function(const char*)
[/error]
--- Code: ---#include <iostream>
class ClassA
{
public:
bool Function ()
{
return true;
}
};
class ClassB : public ClassA
{
public:
bool Function (const char* str)
{
return true;
}
};
int main()
{
ClassB b;
b.Function();
return 0;
}
--- End code ---
I do not understand the compilers problem.
Because A::Function and B:Function has different names because the
signaturs (name+parameters) are different.
Shouldn't it work in iso-c++? Is it a compiler problem or I am wrong
understanding standard c++?
PChris:
You have to pass the parameter as well ;)
e.g: Function("Hello");
MoonKid:
--- Quote from: PChris on April 22, 2006, 02:15:58 pm ---You have to pass the parameter as well ;)
e.g: Function("Hello");
--- End quote ---
No, I do not want to call ClassB::Function. I want to call ClassA::Function. I think the compiler should know that because of the signature.
I know I could call it like that
b.ClassA::Function()
But the compiler should know it by itsefl.
PChris:
I don't really understand you...
If there is a function in ClassB, why should the compiler search the function in ClassA?
MoonKid:
--- Quote from: PChris on April 22, 2006, 02:35:49 pm ---If there is a function in ClassB, why should the compiler search the function in ClassA?
--- End quote ---
The compiler generates symbols (names) for functions while compiletime.
"bool ClassA::Function()" is a different name instead of "bool ClassB::Function(const char*)".
Not because of A and B. Because of the signature of the methodes.
A methode name is generated on functionname+parameters, that is what is called "signature of a function".
That is what I have learned about compilers.
Navigation
[0] Message Index
[#] Next page
Go to full version