-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.cpp
48 lines (40 loc) · 942 Bytes
/
copy.cpp
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
#include <iostream>
using namespace std;
class Car
{
public:
virtual void drive() { cout << "Driving!\n"; }
virtual bool drive(const string& dest) // Overloading / överlagring
{
cout << "Driving to " << dest << endl;
return true;
}
string getLicensePlateNumber() { return "1337"; }
void getLicensePlateNumber(string& name) { name = "1337"; }
};
class RacingCar : public Car
{
public:
virtual void drive() override
{
cout << "Racing!\n";
} // Override / överskuggning
virtual bool drive(const string& dest) override
{
Car::drive();
cout << "Racing to " << dest << endl;
return true;
}
string fancyName;
};
int main()
{
Car* ferrari = new RacingCar();
ferrari->drive();
ferrari->drive("Germany");
// drive()
// drive(const string&)
// drive(string&)
string name;
ferrari->getLicensePlateNumber(name);
}