-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec6_2.cpp
More file actions
49 lines (46 loc) · 763 Bytes
/
Copy pathlec6_2.cpp
File metadata and controls
49 lines (46 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
class Animal
{
public:
// void speak()
// {
// cout<<"huhhh"<<endl;
// }
virtual void speak() = 0; // pure virtual / abstract class
// virtual void speak()
// {
// cout<<"huhhh"<<endl;
// }
};
class Dog : public Animal
{
public:
void speak()
{
cout<<"bark"<<endl;
}
};
class Cat : public Animal
{
public:
void speak()
{
cout<<"Meow"<<endl;
}
};
int main()
{
// Animal *p;
// p = new Dog();
// p->speak();
vector<Animal*>v;
v.push_back(new Dog());
v.push_back(new Cat());
// v.push_back(new Animal());
for(int i=0;i<v.size();i++)
{
v[i]->speak();
}
return 0;
}