blob: c21837bcd1a10cf75d9183db70a39e701cf801aa (
plain)
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
58
59
|
#include "simple-classes.hpp"
#include <iostream>
// implementation for the default constructor
// math::vec3i::vec3i() {
// x = 0;
// y = 0;
// z = 0;
// }
// here is a modern implementation that
// uses a C++11 feature called `member initializers'
math::vec3i::vec3i() : x(0), y(0), z(0) {
// does nothing special
}
// implementation for the copy constructor, that
// copies the other object
math::vec3i::vec3i(const math::vec3i& other) {
// in this case we copy only the components
x = other.x;
y = other.y;
z = other.z;
}
// impl for a custom constructor
math::vec3i::vec3i(int x_, int y_, int z_) {
x = x_;
y = y_;
z = z_;
}
void math::vec3i::zero() {
x = 0;
y = 0;
z = 0;
}
int math::vec3i::dot(const vec3i& other) const {
return x * other.x + y * other.y + z * other.z;
}
int main(int argc, char *argv[]) {
// a vector with zeroes
math::vec3i v;
// a copy of v
const math::vec3i u(v);
// a vector initialized
math::vec3i w(1, 2, 3);
std::cout << u.dot(w) << std::endl;
return 0;
}
|