mercredi 31 mai 2017

c++ - Functional with operator()

Let say I have the following code:

template<typename T> Matrix{
  private:
    int nr;
    std::vector<T> data;
  public:
    T& operator()(const int& j, const int& k){
    return this->mat.at(j+k*nr);}

    const T& operator()(const int& j, const int& k) const {
    return this->mat.at(j+k*nr);}
};

At some point I need to create a function pointer associated to const T& operator()(const int& j) const to use it as an argument in another function. Using functional, I tried:

//#include<functional>
function<const double&(const Matrix<double>&, const int&, const int&)> coef=&Matrix<double>::operator();

and I have the following error:

 no viable conversion from '<overloaded function type>' to 'function<const double &(const
  Matrix<double> &, const int &, const int &)>

I cannot get it to work and it is pretty hard to find informations on function, since the name is quite used...

Aucun commentaire:

Enregistrer un commentaire