Created
November 20, 2023 14:39
-
-
Save HammadMaqbool/a661e9a2a9d1461d6698902eb4064de3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
class Animal | |
{ | |
public: | |
void virtual Speak() | |
{ | |
//no code. . . | |
} | |
}; | |
class Cat : public Animal | |
{ | |
public: | |
void Speak() | |
{ | |
cout<<"Meao Meao"<<endl; | |
} | |
}; | |
class Dog : public Animal | |
{ | |
public: | |
void Speak() | |
{ | |
cout<<"Waof Waof"<<endl; | |
} | |
}; | |
int main() | |
{ | |
Cat cat; | |
Dog dog; | |
Animal* pet; | |
pet = &dog; | |
pet->Speak(); | |
pet = &cat; | |
pet->Speak(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment