I am trying to create a function that takes in a sorted vector of integers, loops through the vector and if there is a value in the vector that is repeated it deletes that entry.

This is what I have so far and I am not too sure how to correct the function to get it working as I get the following error message:

error: type 'int' argument given to 'delete', expected pointer

void checkID(vector <int>& d){

    for (unsigned int i = 0; i < d.size(); i++){
        if(d[i] == d[i+1]){
            delete d[i+1];
        }
    }
}

Please help!

Recommended Answers

you cannot delete a int.
You can delete a pointer.

But here you want to delete something from a vector.
use the vector.erase(iterator position) method.

http://www.cplusplus.com/reference/stl/vector/erase/

Jump to Post

All 5 Replies

Also you can use
d.erase (d.begin()+i+1);
instead of delete d[i+1];

Thanks that worked perfectly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.