Hi All,
I am new to c++, please find my program below and my doubt as mentioned below.
When I call this d1.Test(d2) , its always refers baseclass show funtion( ).Why its refering always base class member funtion. please let me know, what is referring in the backend!
I am new to c++, please find my program below and my doubt as mentioned below.
Code:
#include <iostream>
using namespace std;
class base
{
public:
virtual void Show(void)
{
cout << "base:Show" << endl;
return ;
}
void Test(base obj)
{
obj.Show();
}
};
class derived:public base
{
public:
void Show(void)
{
cout << "derived:Show" << endl;
return ;
}
};
int main(int argc, char **argv)
{
derived d1;
derived d2;
d1.Test(d2);
return 0;
}
When I call this d1.Test(d2) , its always refers baseclass show funtion( ).Why its refering always base class member funtion. please let me know, what is referring in the backend!
Comment