C++ virtual function: Base class function is called instead of derived
Clash 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.