summaryrefslogtreecommitdiffstats
path: root/namespaces.cpp
blob: 2e93b61c305b37ad0af535ee1065dbe099491b29 (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
#include <iostream>

#include "namespaces.hpp"

// to access a namespace the notation is `<namespace>::<element>'
// it is possible to create nested namespaces (!) `<nsA>::<nsB>::elm'
int math::dot(math::vec3i v, math::vec3i w) {
    return v.x * w.x + v.y * w.y + v.z * w.z;
}

// alternatively (but not recommended) we can enclose the code
// in a namespace declaration
namespace math {
    double dot(vec3d v, vec3d w) {
        return v.x * w.x + v.y * w.y + v.z * w.z;
    }
}


int main(int argc, char *argv[]) {

    math::vec3i a = { 1, 2, 3 };
    math::vec3i b = { 1, 2, 3 };
    std::cout << math::dot(a, b) << std::endl;

    // it is also possible to specify to implicitly 
    // always use the namespace in a scope
    {
        using namespace math;

        vec3d c = { .5, .2, 11.2 };
        vec3d d = { .2, .2, 12.3 };
        std::cout << dot(c, d) << std::endl;
    }

    return 0;
}