-
Notifications
You must be signed in to change notification settings - Fork 1
/
list3704.cpp
52 lines (45 loc) · 1 KB
/
list3704.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
49
50
51
52
#include<iostream>
#include<vector>
class base{
public:
base(int value) : value_{value} {std::cout<<"base(" << value << ")\n";}
base():base{0}{std::cout<<"base()\n";}
base(base const& copy)
:value_{copy.value_}
{std::cout<<"copybase(" << value_<< ")\n";}
~base(){std::cout<<"~base("<< value_<< ")\n";}
int value()const{return value_;}
base& operator++()
{
++value_;
return *this;
}
private:
int value_;
};
class derived : public base{
public:
derived(int value):base{value}{std::cout<<"derived("<<value<<")\n";}
derived():base{}{std::cout<<"derived()\n";}
derived(derived const& copy)
:base{copy}
{std::cout<<"copy derived("<<value()<<"\n";}
~derived(){std::cout<<"~derived("<<value()<<")\n";}
};
derived make_derived(){
return derived{42};
}
base increment(base b){
++b;
return b;
}
void increment_reference(base& b){
++b;
}
int main(){
derived d{make_derived()};
base b{increment(d)};
increment_reference(d);
increment_reference(b);
derived a(d.value()+b.value());
}