my program returns a run time error and I'd be pleased if you help me to figure up the problem.
I have a vector of pointers to myClass (which is sorted due to myClass.value) and I'd like to insert a new object instead of the element in the vector with the biggest value.
like this:
while a new value arrives (myClass1.value < newVal < myClass2.value), the last element (myClass3) is removed and a new myClass is inserted with its newVal at the right position in the sorted list (between myClass1 and myClass2).
myVector (a sorted vector due to the field: value)
|
|->myClass1__
| |__value
|
|->myClass2__
| |__value
|
|->myClass3__
|__value
ne555,
please offer your idea, I used a vector of pointers to myClass in order to maintain some elements of myClass. do you suggest to use a vector of myClass rather then a vector of pointers to myClass? if yes, how the code looks like?
You will not delete anything here, there will be no memory leaks, you only need to dereference the iterators once.
However insert and erase will cost you more if the class is big (although if you do that a lot maybe a list is better)