-
Notifications
You must be signed in to change notification settings - Fork 36
/
example.cpp
40 lines (31 loc) · 956 Bytes
/
example.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
#include <iostream>
#include <vector>
#include "../include/nft_ptr.hpp"
using ::wdb::make_nft;
using ::wdb::nft_ptr;
class Animal {
public:
virtual ~Animal();
virtual void MakeSound() = 0;
};
Animal::~Animal() {}
class Cow : public Animal {
public:
virtual void MakeSound() override;
};
void Cow::MakeSound() { std::cout << "Moo!" << std::endl; }
int main(int argc, char** argv) {
std::cout << "Creating ptr1!" << std::endl;
auto ptr1 = make_nft<Cow>();
std::cout << "ptr1(" << &ptr1 << "): " << ptr1.get() << std::endl;
ptr1->MakeSound();
std::cout << "Creating ptr2!" << std::endl;
nft_ptr<Animal> ptr2;
std::cout << "ptr2(" << &ptr2 << "): " << ptr2.get() << std::endl;
std::cout << "Moving: ptr2 = std::move(ptr1)" << std::endl;
ptr2 = std::move(ptr1);
std::cout << "Moved: ptr1 = " << ptr1.get() << " ptr2 = " << ptr2.get()
<< std::endl;
std::cout << "Destroying objects" << std::endl;
return 0;
}