c ++ error 'const class std :: vectorNode' has no member named 'find';

0

I'm using a structure of set that contains a vector , which in turn contains an object of a class called Nodo , when I try to use the function find() of the vector of the stl me There is an error, consider that it is a function of Nodo and that it should be in that class.

I have included all the necessary files and libraries. Code:

if((*lista_cerrada.end()).find((*lista_cerrada.end()).begin(),(*lista_cerrada.end()).end(),ns)==(*lista_cerrada.end()).end())
                (*lista_cerrada.end()).push_back(ns);

Error:

error: ‘const class std::vector<Nodo>’ has no member named ‘find’; did you mean ‘cend’?

Thanks

    
asked by AER 13.11.2018 в 01:43
source

1 answer

2

You have the error because the class vector does not have any method find . Only ordered containers have this method.

For the rest of the containers you have at your disposal the std::find method in the library algorithm :

if( std::find(std::begin(vector),std::end(vector),ns) == std::end(vector) )
  vector.push_back(ns);

On the other hand, be very careful ... end() , usually return an invalid iterator . end() represents the first position that no longer belongs to the collection ... so the line you mention, if it works, will give you errors at runtime. end() should only be used when comparing iterators.

    
answered by 13.11.2018 / 07:38
source