Why is this not compiling?
error C2660: ‘Concrete::WriteLine’ : function does not take 1 arguments
I know if i add the Line:
//using AbstractBase::WriteLine;
it works, but i dont understand why.
#include "iostream"
class AbstractBase
{
public:
virtual void WriteLine() = 0;
virtual void WriteLine( int i )
{
std::cout<<"AbstractBase"<<std::endl;
}
};
class Concrete : public AbstractBase
{
public:
//using AbstractBase::WriteLine;
virtual void WriteLine()
{
std::cout<<"Concrete Sub Class"<<std::endl;
}
};
int main()
{
Concrete ff;
ff.WriteLine();
ff.WriteLine(1);
return 0;
}
Can someone explain me what happens here.
Thanx
Does anyone knows if this behavior is a defined behavior from the C++ standart.
Is it mentioned in the C++ standart?
Or is it just a kind of compiler behavior?
Once you declare a function:
in derived class it hides all the base class functions with the same name.
The above function which takes no parameters hides the function with same name and taking one parameter, Since compiler cannot find a function with one parameter it reports a error.
The line:
enables(brings in scope) all the hidden names from the Base class in your derived class and hence the function taking one parameter is available.
Good Read:
What’s the meaning of, Warning: Derived::f(char) hides Base::f(double)?