std::set - How do i alter element in list?

How do i alter an element in the set for example how do i edit the 'm_a' member variable of a element in my set?

class CPerson
int m_a;

CPerson(int _a)
m_a = _a;

set<CPerson*> myPersonSet;
set<CPerson*>::iterator it = myPersonSet.find( CPerson(20) );

// How do i change the value of the object i found in my list once i found it and it's referenced by my iterator?
Dereferencing the iterator gives you a pointer to a CPerson, so I think it would be something like this

(*it)->m_a = 42;
A set element once inserted cannot be changed. You can erase it and insert a new one so it looks like "changing" it

Last edited on
Topic archived. No new replies allowed.