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

Multi tool use
Multi tool use
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.

tiJRPRvJMXmRGR9HzbRbK,P3cwMafGwTnQC,dg,nNZVUEU3lth5B3sZ8QbzBe6dGd
xP,E4EQErrYzey C5

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results