-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveable_resources.cpp
More file actions
57 lines (47 loc) · 1.49 KB
/
Copy pathmoveable_resources.cpp
File metadata and controls
57 lines (47 loc) · 1.49 KB
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
53
54
55
56
57
//
// Created by Jonathan Hollocombe on 07/06/2016.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
struct File {
File(const std::string& file_name) : fid_(fopen(file_name.c_str(), "w")) {}
~File() { fclose(fid_); }
// Move constructor
File(File&& other) {
fid_ = other.fid_;
other.fid_ = nullptr;
}
// Make this non-copyable
File(const File&) = delete;
File& operator=(const File&) = delete;
FILE* fid() { return fid_; }
private:
FILE* fid_ = nullptr;
};
int main()
{
File file{ "myfile.txt" };
// File new_file = file;
File new_file = std::move(file);
std::cout << file.fid() << std::endl;
std::cout << new_file.fid() << std::endl;
std::vector<File> files;
files.emplace_back("myfile.txt");
files.push_back(File{"myfile.txt"});
return 0;
}