Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b2b3a39

Browse files
runtime overloading
1 parent 7486522 commit b2b3a39

File tree

1 file changed

+58
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 15 Polymorphism/Function_overloading/Runtime_polymorphism

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Car
6+
{
7+
public:
8+
virtual void start()
9+
{
10+
cout<<"Start() in Car"<<endl;
11+
}
12+
13+
virtual void stop()
14+
{
15+
cout<<"Stop() in Car"<<endl;
16+
}
17+
};
18+
19+
class Skoda : public Car
20+
{
21+
public:
22+
void start()
23+
{
24+
cout<<"Start() from Skoda"<<endl;
25+
}
26+
27+
void stop()
28+
{
29+
cout<<"Stop() from Skoda"<<endl;
30+
}
31+
};
32+
33+
class Renault : public Car
34+
{
35+
public:
36+
void start()
37+
{
38+
cout<<"Start() from Renault"<<endl;
39+
}
40+
41+
void stop()
42+
{
43+
cout<<"Stop() from Renault"<<endl;
44+
}
45+
};
46+
47+
int main(void)
48+
{
49+
Car *c = new Skoda();
50+
c->start();
51+
c->stop();
52+
53+
c = new Renault();
54+
c->start();
55+
c->stop();
56+
57+
return 0;
58+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /