about non-virtual func. in derived class
I have a question about polymorphism.
This is code
Code:
#include <iostream>
using namespace std;
class Pet {
public: virtual void speak() const ;
};
void Pet::speak() const { cout << "Hi" << endl; }
class Dog : public Pet {
public: void speak() const { cout<<"hi too";}
void eat() const { cout<<"eat"; }
};
int main() {
Dog simba; Pet* p=&simba; p->speak();//I can call dog::speak by pet pointer
//p->eat(); but I can not call dog::eat() by pet.
}
here how can i solve the problem.I mean i want to enhance my derived class and call my functions from base class pointer?
Is there a solution?
Thanks...