diff options
author | Nao Pross <naopross@thearcway.org> | 2018-12-10 14:07:47 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-12-10 14:07:47 +0100 |
commit | 1b8b997fc59bf2f443ed34d22cb2d39b0772574f (patch) | |
tree | 6b42f40802401812fbe14f395cdc87ec0b5fb45d /vector | |
parent | Simplified vector by inheriting std::array instead of having m_data (diff) | |
download | cplusplus-1b8b997fc59bf2f443ed34d22cb2d39b0772574f.tar.gz cplusplus-1b8b997fc59bf2f443ed34d22cb2d39b0772574f.zip |
Fix vector copy constructors
Diffstat (limited to 'vector')
-rw-r--r-- | vector/vector.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/vector/vector.cpp b/vector/vector.cpp index f422db2..0322ee2 100644 --- a/vector/vector.cpp +++ b/vector/vector.cpp @@ -36,7 +36,7 @@ basic_vec<T, d>::basic_vec(const basic_vec<T, n>& other) { static_assert(d >= n); this->fill(static_cast<T>(0)); for (std::size_t i = 0; i < n; i++) { - this[i] = other[i]; + this->at(i) = other.at(i); } } @@ -103,12 +103,19 @@ template<typename T, std::size_t d> class vec: public basic_vec<T, d> { public: vec(std::initializer_list<T> l) : basic_vec<T, d>(l) {} + + template<std::size_t n> + vec(const basic_vec<T, n>& other) : basic_vec<T, d>(other) {} }; template<typename T> class vec3 : public basic_vec<T, 3> { public: vec3(std::initializer_list<T> l) : basic_vec<T, 3>(l) {} + + template<std::size_t n> + vec3(const basic_vec<T, n>& other) : basic_vec<T, 3>(other) {} + static vec3<T> cross(const vec3<T>& rhs, const vec3<T>& lhs); }; @@ -125,6 +132,10 @@ template<typename T> class vec2: public basic_vec<T, 2> { public: vec2(std::initializer_list<T> l) : basic_vec<T, 2>(l) {} + + template<std::size_t n> + vec2(const basic_vec<T, n>& other) : basic_vec<T, 2>(other) {} + T angle(); static vec3<T> cross(const vec2<T>& rhs, const vec2<T>& lhs); }; |