Commit d0e55e33637456a7839a970658d12074be22b4b6
1 parent
c7fae41f
unique_ptr in ival_box example
Showing
2 changed files
with
7 additions
and
5 deletions
examples10/04-qtival/boxfactory.cpp
1 | #include <iostream> | 1 | #include <iostream> |
2 | +#include <memory> | ||
2 | using namespace std; | 3 | using namespace std; |
3 | 4 | ||
4 | #include "qt_ival_box.h" | 5 | #include "qt_ival_box.h" |
5 | #include "text_ival_box.h" | 6 | #include "text_ival_box.h" |
6 | 7 | ||
7 | 8 | ||
8 | -Ival_box* ivalBoxFactory() | 9 | +unique_ptr<Ival_box> ivalBoxFactory() |
9 | { | 10 | { |
10 | if (getenv("DISPLAY")) | 11 | if (getenv("DISPLAY")) |
11 | - return new QT_ival_slider; | 12 | + return make_unique<QT_ival_slider>(); |
12 | else | 13 | else |
13 | - return new Text_ival_box; | 14 | + return make_unique<Text_ival_box>(); |
14 | } | 15 | } |
15 | 16 |
examples10/04-qtival/code.cpp
1 | #include <iostream> | 1 | #include <iostream> |
2 | +#include <memory> | ||
2 | using namespace std; | 3 | using namespace std; |
3 | 4 | ||
4 | #include "ival_box.h" | 5 | #include "ival_box.h" |
5 | 6 | ||
6 | -Ival_box* ivalBoxFactory(); | 7 | +unique_ptr<Ival_box> ivalBoxFactory(); |
7 | 8 | ||
8 | void fun() | 9 | void fun() |
9 | { | 10 | { |
10 | - Ival_box* s = ivalBoxFactory(); | 11 | + auto s = ivalBoxFactory(); |
11 | s->reset_value(12); | 12 | s->reset_value(12); |
12 | s->prompt(); | 13 | s->prompt(); |
13 | cout << s->get_value() << endl; | 14 | cout << s->get_value() << endl; |