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]
#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;
}
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++?
class ClassB : public ClassA
{
public:
using ClassA::Function;
bool Function (const char* str)
{
return true;
}
};
Your problem is the compiler hides A::Function and it's natural C++ behavior.
You could have lots of different signatures of Function in ClassA. If you make ClassB inherit from ClassA, ClassB will have all those Function too, but if you add a method in ClassB with the name Function (just what you're doing), every inherited signature of Function will be hidden.
To make ClassA::Function visible in ClassB do this (Thomas was faster):
class ClassB : public ClassA
{
public:
using ClassA::Function;
bool Function (const char* str)
{
return true;
}
};
Another way is to change your main to this:
int main()
{
ClassB b;
b.ClassA::Function();
return 0;
}