mercredi 24 novembre 2021

Adding a member to std::vector

I have to modify a code so that I can add a member to 2D vectors. The code started with a typedef vector<vector<int>> Matrix which I replaced with a Matrix class. I tried to inherit from vector<vector<int>> using :

class Matrix: public vector<vector<int>> {
public:
    int myMember;
};

This way I practically don't have to modify the source code much. However, if I try to run :

Matrix mymatrix (4);

It raises an error :

modele.cpp:19:20: error: no matching function for call to 'Matrix::Matrix(int)'
  Matrix mymatrix (4);
                    ^
In file included from modele.cpp:8:0:
modele.h:6:7: note: candidate: Matrix::Matrix()
 class Matrix: public vector<vector<int>> {
       ^
modele.h:6:7: note:   candidate expects 0 arguments, 1 provided

Aucun commentaire:

Enregistrer un commentaire