c++ - Can't initialize valarray as private member of class -


i'm trying implement class contains valarray , 2 ints define size. hpp file looks this:

class matrix { public:     // constructors     matrix();     matrix(int width, int height);      // mutators     void setwidth(int width);               // post: width of matrix set     void setheight(int height);             // post: height of matrix set     //void initva(double width);      // accessors     int getwidth();                         // post: returns number of columns in matrix     int getheight();                        // post: returns number of rows in matrix      // other methods     //void printmatrix(const char* lbl, const std::valarray<double>& a);  private:      int width_;     int height_;     std::valarray<double> storage_; }; 

however, when try initialize valarray on constructor this:

matrix::matrix(int width, int height) {     width_ = width;     height_ = height;     storage_(width*height); } 

i keep getting error message:

error c2064: term not evaluate function taking 1 arguments

the documentation says can declare valarray in @ least 5 different ways, default contructor works. i've looked everywhere haven't been able find useful info. appreciated.

you trying invoke std::valarray<double>::operator()(int) here, no such operator exists. presumably, meant use initializer list instead:

matrix::matrix(int width, int height)     : width_(width),       height_(height),       storage_(width*height) { } 

alternatively, can assign new object instance instead, less performant using initializer list, storage_ default-constructed, , replaced copy of new temporary, , temporary destructed. (a decent compiler may able eliminate of these steps, not rely on that.)

storage_ = std::valarray<double>(width*height); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -