diff --git a/td/td5/include/matrice.h b/td/td5/include/matrice.h new file mode 100644 index 0000000..41bc099 --- /dev/null +++ b/td/td5/include/matrice.h @@ -0,0 +1,13 @@ +#include "vector.h" + +constexpr size_t MAX_MAT = 10; + +class Matrice { + public: + Matrice(); + ~Matrice(); + Vector*& operator[](const int indice); + friend std::ostream& operator<<(std::ostream& stream, const Matrice& mat); + private: + Vector* _vectors[MAX_MAT]; +}; \ No newline at end of file diff --git a/td/td5/src/main.cpp b/td/td5/src/main.cpp index 5b6e1b3..eea4c75 100644 --- a/td/td5/src/main.cpp +++ b/td/td5/src/main.cpp @@ -1,8 +1,8 @@ #include "../include/vector.h" #include "../include/smart_vector.h" #include "../include/deque.h" -// Joker : slice.h -// Joker : vector_iteraor.h +#include "../include/matrice.h" + #include int main(void) @@ -10,5 +10,22 @@ int main(void) Vector floatVect(4,3.5f); std::cout << floatVect * 9.0f << std::endl; std::cout << 9.0f * floatVect << std::endl; + + Matrice mat; + + mat[0] = new Vector(6,30.0f); + //mat[1] = &floatVect; + // This leads to pointer error when calling the ~Matrice() func. + mat[2] = new Smart_Vector(7, 20.0f); + + /* + auto multipleVect = new Vector[2]; + for(size_t i = 0; i< 2 ; i++) + multipleVect[i].PushBack(1.9); + mat[3] = multipleVect; + */ + // This leads to an error because each Vector should not be an array but only a pointer. + + std::cout << mat << std::endl; return 0; } \ No newline at end of file diff --git a/td/td5/src/matrice.cpp b/td/td5/src/matrice.cpp new file mode 100644 index 0000000..90191e3 --- /dev/null +++ b/td/td5/src/matrice.cpp @@ -0,0 +1,31 @@ +#include "../include/matrice.h" +#include + +Matrice::Matrice() +{ + for(size_t i=0; i*& Matrice::operator[](const int indice) +{ + if((indice > 10) || (indice < 0)) + throw "A Matrix is composed of 10 arrays of vectors."; + return _vectors[indice]; +} + +std::ostream& operator<<(std::ostream& stream,const Matrice& mat) +{ + for(size_t i=0; i