Delete object from Vector, how?

I have a class to create objects and a Vector to store them in. No I want a function to search and erase specific objects from the vector.

I've done this:

In my class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Film
{
    string Titel;
    string Media;

....

    void eraseFilm(string Titel, vector<Film>&Arkiv)
    {
        for(int i=0; i!=Arkiv.size(); i++)
        {
            if(Arkiv[i].Titel == Titel)
            {
                Arkiv.erase(Arkiv.begin()+i, Arkiv.begin()+1+i);
                break;
            }
        }
    }

....

};


In my main function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
    vector<Film> Arkiv;

....

    // In a switch case, I have a function call set up like this:

    case '2':
        {
            string radera;

            getline(cin, radera);

            Film eraseFilm(radera);    // Not working...?
        }

....

    return 0;
}


Error:

no matching function for call to 'Film::Film(std::string&)'

Note:

candidates are: Film::Film()
Film::Film(const Film&)


Please tell if you need more information about the problem.

Thanks in advance!
Film eraseFilm(radera); constructs a `Film' object called `eraseFilm'.


1
2
Film foo;
foo.eraseFilm(radera, Arkiv); //respect the prototype 
It makes no sense for it to be a method
Thanks alot!
It makes no sense for it to be a method


Agreed, you would want something more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Film
{
  string title;
  string media;
};

class Database
{
  vector<Film> films;

  void remove(Film& toBeRemoved) // or whatever arguments you want
  {
    //code to remove
  }
};

Last edited on
Topic archived. No new replies allowed.