-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (32 loc) · 933 Bytes
/
main.cpp
File metadata and controls
45 lines (32 loc) · 933 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
44
45
#include "Grid.hpp"
#include <vector>
#include <memory>
#include <iostream>
using namespace std;
void processIntGrid(Grid<int>& /*grid*/)
{
// ...
}
int main()
{
Grid<int> myIntGrid;
Grid<double> myDoubleGrid(11, 11);
myIntGrid.at(0, 0) = 10;
int x = myIntGrid.at(0, 0).value_or(0); // with optional :)
Grid<int> grid2(myIntGrid); // copy operator
Grid<int> anotherIntGrid;
anotherIntGrid = grid2; // = operator
//Grid test; // compile error
//Grid<> test; // compile error
processIntGrid(myIntGrid);
Grid<const char*> myStringGrid;
myStringGrid.at(2, 2) = "hello";
Grid<vector<int>> gridOfVectors;
vector<int> myVector{ 1, 2, 3, 4 };
gridOfVectors.at(5, 6) = myVector;
auto myGridOnHeap = make_unique<Grid<int>>(2, 2); // 2x2 Grid in heap memory pool.
myGridOnHeap->at(0, 0) = 10;
x = myGridOnHeap->at(0, 0).value_or(0);
std::cout << "Template Class with .hpp + .cpp" << '\n';
return 0;
}