c++ - *this-> can not be used as a function -


here's excerpt of class have created inside header file :

typedef double real;  class grid{    public :        explicit grid ();       explicit grid(size_t level );       grid(const grid & grid );        ~ grid ();         const grid & operator =( const grid & grid );        inline real & operator ()( size_t , size_t j );       inline real operator ()( size_t ,size_t j ) const;        void fill( real value );       void setboundary ( real value );   private :     size_t y_ ; // number of rows     size_t x_ ; // number of columns     real h_ ; // mesh size     real * v_ ; //  values  }; 

and here's excerpt code have written declared functions in separate .cpp file. note have included parts relevant error.

  inline real&  grid :: operator ()( size_t , size_t j ){     if( (i >= y_) || (j>=x_ ) )       throw std::invalid_argument( "index out of bounds" );     return v_ [i* x_ +j];   }    inline real grid::operator ()( size_t ,size_t j ) const{     if( (i >= y_) || (j>=x_ ) )       throw std::invalid_argument( "index out of bounds" );     return v_[i* x_+j];   }     void grid::fill( real value ){    for(size_t i=1;i<y_;++i){     for(size_t j=1;j<x_;++j)      v_(i,j)=value;    }    }   void grid::setboundary ( real value ){     size_t = 0;     for(size_t j=0;j<x_;++j){      v_(i,j)=value;     }     = y_;     for(size_t j=0;j<x_;++j){      v_(i,j)=value;     }     size_t j = 0;     for(size_t i=0;i<y_;++i){      v_(i,j)=value;     }     j = x_;     for(size_t i=0;i<y_;++i){      v_(i,j)=value;     }   } 

i getting error

((grid*)this)->grid::v_ cannot used function

whenever trying use overloaded () operator, inside fill , setboundary function. have tried looking similar errors online, unfortunately couldn't make progress. have suggestions, because think implementation of overloaded operator correct , far know haven't named function same name member variable.

v_ real*, i.e. pointer. pointers don't have operator(), can't write v_(something).

you've provided overload of operator() grid class. if want use overload, need use () on object of grind class. v_ not object of grid class.

you want invoke operator() on current object (i.e. object fill or setboundary being called on). that, you'd write (*this)(arguments).


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -