pointers - Pass value pointed by non-const iterator by reference c++ -


i have std::set<mytype> container i'm getting function of class, i.e. have somethig this:

typedef std::set<mytype, comparemytype> mytypeset;   // singleton class class myclass {   ...   public:       mytypeset& getmyset() { return myset_; }   ...   private:   mytypeset myset_;   ...   }   

then in other place i'm using container:

myclass obj; mytypeset& myset = mtyobj->getmyset(); mytypeset::iterator itbeg = myset.begin(); // i'm trying call f function f(*itbeg); 

where f function has signature below:

void f(mytype& param); 

i'm getting compilation error this:

note: candidates are: void f(mytype&) error: no matching function call f(const mytype&) 

how can fix this?
in advance.

without knowing details environment, i'm guessing system's implementation of set attempts "safe" aliasing iterator const_iterator (so don't try modify set items via iterator, dangerous because might change sort order). see here more this.

if so, easiest fix change signature of function void f(const mytype& param) compiler suggests. if do really need modify parameter (in such way not change sort order), there variety of hacks around const restriction (including using const_cast or solution suggested @ above link), recommend proceeding caution.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -