Commit d0e55e33637456a7839a970658d12074be22b4b6

Authored by Grzegorz Jabłoński
1 parent c7fae41f

unique_ptr in ival_box example

examples10/04-qtival/boxfactory.cpp
1 1 #include <iostream>
  2 +#include <memory>
2 3 using namespace std;
3 4  
4 5 #include "qt_ival_box.h"
5 6 #include "text_ival_box.h"
6 7  
7 8  
8   -Ival_box* ivalBoxFactory()
  9 +unique_ptr<Ival_box> ivalBoxFactory()
9 10 {
10 11 if (getenv("DISPLAY"))
11   - return new QT_ival_slider;
  12 + return make_unique<QT_ival_slider>();
12 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 1 #include <iostream>
  2 +#include <memory>
2 3 using namespace std;
3 4  
4 5 #include "ival_box.h"
5 6  
6   -Ival_box* ivalBoxFactory();
  7 +unique_ptr<Ival_box> ivalBoxFactory();
7 8  
8 9 void fun()
9 10 {
10   - Ival_box* s = ivalBoxFactory();
  11 + auto s = ivalBoxFactory();
11 12 s->reset_value(12);
12 13 s->prompt();
13 14 cout << s->get_value() << endl;
... ...