debugging - Passing unique_ptr to non-member functions -


i having troble figuring our how pass around smart pointer.

i call function isidentity on matrix object h:

void test(const size_t dim) {     cout << "identity gen: " << "\t\t" << ((h.isidentity())?"true":"false") << endl; } 

here matrix class relevant functions. have member function called isidentity , private array called m contain actual matrix.

template <typename t>  class matrix  { private:     size_t dim;     unique_ptr<t[]> m;  public:     explicit matrix(size_t dim) : dim(dim), m(new t[dim*dim]())     {         m = gen_mat<t>(dim); //generates random matrix     }     matrix(t* m, size_t dim):  dim(dim), m(m){} //copy constructor     ~matrix(){       };      bool isidentity()     {         return check_identity<t>(this->m,dim);     } } 

the member function calles non-member function.

template <typename t>  bool check_identity(const t *m, size_t dim) {     for(size_t = 0; < dim; ++i)     {         for(size_t j = 0; j < dim; ++j)         {             t r = == j ? m[i*dim+j] - 1.0 : m[i*dim+j];             if (r < -precision || r > precision)             {                 return false;             }         }     }     return true; } 

question:

for reason check_identity function not recognized. uncertain if approach proper way it. can explain me wrong , give guidelines on how right?

please comment if additional information required.

error message:

error: no matching function call ‘check_identity(std::unique_ptr<double [], std::default_delete<double []> >&, size_t&)’ 

your function takes plain pointer. there no implicit conversion smart pointer plain pointer. explicit conversion carried out member function get

return check_identity<t>(this->m.get(),dim);                              ///^^^^^ 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -