0

The error is "No Instance of overloaded function ... matches the argument list" I understand that i give wrong argument to the erase function, but i do not know how to fix that

    void Folder::DeleteFolder(Folder* folder)
    {
     for(int i = 0; i> (this->Folder::GetFolders().size());i++)
     {
          if(this->Folder::GetFolders()[i]==folder)
          {
             //The problem occures on the next line
             this->Folder::GetFolders().erase(this->Folder::GetFolders()[i]);
             break;
          }
     } 
    }

   //here is the method GetFolders
   std::vector<Folder*>& Folder::GetFolders()
   {
     return this->listOfFolders;
   }
manlio
  • 18,345
  • 14
  • 76
  • 126
user3593131
  • 1
  • 1
  • 1

2 Answers2

1

First of all I think that you mean comparison of the object pointed to by folder with objects in tthe vector.

The general approach to do the task is by using standard algorithm std::find_if The code will look the following way

void Folder::DeleteFolder(Folder* folder)
{
    std::vector<Folder*> &v =  this->Folder::GetFolders();

    auto it = std::find_if( v.begin(), v.end(),
                            [&]( Folder *f ) { return ( *f == *folder ); } );

    if ( it != v.end() ) v.erase( it );
} 
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

Edit:

You can simply use:

     std::vector<Folder*>::iterator itr= listOfFolders.begin();
     while( itr != listOfFolders.end())
     {
       if(*itr==folder){
          listOfFolders.erase( itr );
          break;
       }
       ++itr;
     }
Rakib
  • 7,435
  • 7
  • 29
  • 45