Incompatible Class Declaration c++ -


i have class numberarray in numberarray.h

class numberarray { private:   double *aptr;   int arraysize;  public:   numberarray(int size, double value);    // ~numberarray() { if (arraysize > 0) delete [ ] aptr;}   //commented out avoid problems   //default copy constructor   void print() const;    void setvalue(double value); }; 

when go write print function in numberarray.cpp

void numberarray::print() {   (int index = 0; index < arraysize; index++)     cout << aptr[index] << "  "; } 

it gives me error

declaration incompatible "void numberarray::print() const

any thoughts might going wrong on this? rest of constructors , class functions work fine.

you forgot add const qualifier (as semicolon) signature of definition of function.

you have do:

void numberarray::print() const {   (int index = 0; index < arraysize; index++)     cout << aptr[index] << "  "; } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -