Skip to content

Instantly share code, notes, and snippets.

@HammadMaqbool
Created November 20, 2023 14:39
Show Gist options
  • Save HammadMaqbool/a661e9a2a9d1461d6698902eb4064de3 to your computer and use it in GitHub Desktop.
Save HammadMaqbool/a661e9a2a9d1461d6698902eb4064de3 to your computer and use it in GitHub Desktop.
#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