-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.53.cpp
48 lines (40 loc) · 834 Bytes
/
16.53.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 "print.h"
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
class Base {
public:
Base(const string &s = "") : name(s) {}
virtual ~Base() = default;
virtual std::string rep() const {
return name;
}
protected:
string name;
};
class Derived final : public Base {
public:
Derived() : Base(), value(0) {}
Derived(const string &s, int i) : Base(s), value(i) {}
std::string rep() const override {
return name + std::to_string(value);
}
private:
int value;
};
std::ostream &operator<<(std::ostream &os, const Base &b) {
return os << b.rep();
}
int main() {
int i = 12;
double d = 1.2;
string s = "word";
Base obj1("Base");
Derived obj2("Derived", 12);
print(cout, i) << endl;
print(cout, i, d, s) << endl;
print(cout, i, d, s, obj1, obj2) << endl;
return 0;
}