C++ virtual function: Base class function is called instead of derived

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


C++ virtual function: Base class function is called instead of derived



I have following code snippet:


using namespace std;
class base
{
public:
virtual void print(char a){ std::cout<<" Base "<<std::endl;}
};
class derived :public base
{
public:
void print(floata) {std::cout<<" Derived "<<std::endl;}
};

int main()
{
base* d = new derived;
d->print(1.5);

return 0;
}



Output is "base"
Why output is coming from base function and not from derived one









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

C# - How to create a semi transparent or blurred backcolor on windows form

Swipe gestures in WKWebView

How to populate data on nav-tab in partial View in MVC?