#include<iostream>
using namespace std;
class A
{
public:
A() {
}
virtual void m()
{
cout << "BASE Default" << endl;
}
virtual void m(int i)
{
cout << "BASE 1 Arg" << endl;
}
virtual void m(int i,char c)
{
cout << "BASE 2 Arg" << endl;
}
};
class B : public A
{
public:
B(){}
void m()
{
cout << "Der Default" << endl;
}
void m(int i,char c)
{
cout << "BASE 2 Arg" << endl;
}
};
int main()
{
B b;
b.m(25);
return 0;
}
The output of above code is:
sample.cpp: In function int main():
sample.cpp:37: error: no matching function for call to B::m(int)
sample.cpp:25: note: candidates are: virtual void B::m()
sample.cpp:29: note: virtual void B::m(int, char)
I was expecting output as "BASE 1 Arg" since if we don't override any base virtual function then derived class will have the definition defined in base class for that function.so can anybody explain the reason for this behavior.

New Topic/Question
Reply




MultiQuote



|