jeudi 29 décembre 2016

declare bidirectional matrix using smart pointers in C++

I want to know how to declare a bidirectional array in C++ using smart pointers.. I menage with raw pointers. The code is:

class Matrice{

int size;
int **val;

public:
    Matrice(int size1)
    {
        val = new int* [size1];
        size = size1;
              for (int i = 0; i < size1; i++)
              {
                 val[i] = new int[size1];
              }
              for (int i = 0; i < size1; i++){
                 for (int j = 0; j < size1; j++)
                 {
                    val[i][j] = j;
                 }
              }

    }

    ~Matrice()
    {
        delete []val;
        cout<<"Destroyed matrix! \n";
    }

};

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire