I have this simple class:
class MyClass {
public:
int id;
string name;
};
I want to have a vector with pointers to objects of this class that is sorted by the referenced MyClass
id
. I thought that using lower_bound
would be easy, I did it before with vectors of objects (not pointers). With objects, I overloaded operator<
like that:
bool operator<(MyClass left, int right) {
return (left.id < right);
}
Then I used lower_bound
to insert new MyClass
object to sorted vector.
vector<MyClass>::iterator low;
low = lower_bound(vectorname.begin(),vectorname.end(),id);
prP = idContainer.begin();
prP = idContainer.insert(low, newobject);
I am lost how to do the same with the vector of MyClass
pointers. Can anyone help me achieve that?