-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (35 loc) · 787 Bytes
/
main.cpp
File metadata and controls
43 lines (35 loc) · 787 Bytes
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
#include <iostream>
#include <cassert>
#include "global.h"
class Matrix
{
public:
Matrix() {}
Matrix transpose() const { return Matrix{}; }
};
global<Matrix> gMatrix;
void transpose(Matrix& m)
{
m.transpose();
}
int main()
{
// First, the global variable must be initialized
assert(!gMatrix.exists());
gMatrix.init(/* arguments to class Matrix*/);
assert(gMatrix.exists());
try {
gMatrix.init();
}
catch(const std::runtime_error&)
{
std::cout << "Double init throws\n";
}
// Use the global variable of type Matrix
gMatrix.with(transpose);
// Lastly the global variable must be destroyed
gMatrix.reset();
assert(!gMatrix.exists());
std::cout << "Completed with no errors.\n";
return 0;
}