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

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 meeting, networking, learning, and sharing knowledge.