class - c++ call functions in copy constructor -


i have

public:     largersetpartd(unsigned maxvalue);     largersetpartd(const largersetpartd &);  //copy constructor     void printelements();               // prints members     void set_union(const largersetpartd &);     bool ismember(unsigned int); private:     unsigned long values;     unsigned maxelementvalues; 

in set_union trying do

largersetpartd *temparray = new largersetpartd(maxelementvalue); //this part of code saves old array composed of values temparray. if ( temparray->ismember(i) || other.ismember(i)) 

however other.ismember(i) not working. tried other->ismember(i) , doesnt work. can not touch/change public functions cant add const in member. im not sure do. appreciated. error message is

passing ‘const largersetpartd’ ‘this’ argument discards qualifiers [-fpermissive]  copy constructor: largersetpartd::largersetpartd(const largersetpartd &other) {          values = other.values;         maxelementvalue = other.maxelementvalue; } 

assuming other const largersetpartd & argument set_union, trying call non-const method on const object, not permitted.

since can't change signature of public methods, create temporary non-const copy of other , call method on that:

largersetpartd tmp_other(other); if ( temparray->ismember(i) || tmp_other.ismember(i))     ... 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -