User forums > General (but related to Code::Blocks)
do I understand C++ wrong?
sethjackson:
The ClassB::Function(const char* str) is different than the ClassA::Function(). You declare ClassB, and then try not passing a param to Fuction(const char* str). You cannot do this since Fuction(const char* str) requires a param. Some C++ guru could answer this better I'm sure, but that is the way the compiler works AFAIK. So why don't you declare ClassA, and call that Function()?
MoonKid:
--- Quote from: sethjackson on April 22, 2006, 03:16:45 pm ---So why don't you declare ClassA, and call that Function()?
--- End quote ---
I want to have an object with a to Function() methodes, one with and one without a parameter.
Logicly (in my framework) they should be in different classes.
I will think about how to design it compilable
thomas:
--- Code: ---class ClassB : public ClassA
{
public:
using ClassA::Function;
bool Function (const char* str)
{
return true;
}
};
--- End code ---
Ceniza:
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):
--- Code: (cpp) ---class ClassB : public ClassA
{
public:
using ClassA::Function;
bool Function (const char* str)
{
return true;
}
};
--- End code ---
Another way is to change your main to this:
--- Code: (cpp) ---int main()
{
ClassB b;
b.ClassA::Function();
return 0;
}
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version