Meaning of this syntax

Asked

Viewed 116 times

0

I need to continue a job that is partially ready. However I did not find on the internet files that described or taught this in an understandable way. What is the meaning of this syntax ? Ide: Netbeans and C Language++

void Grafo::buscarElosEmProfundidade(No *origem, std::function<bool(No*, No*, Elo*)> func)

The part At the origin I understand it to be a pointer, but what about this part of Std::functio bool(No *, No *, Elo *) func)? what does it mean ?

The complete function is this :

void Grafo::buscarElosEmProfundidade(No *origem, std::function<bool(No*, No*, Elo*)> func){
ListaParEloPercorrido *percorridos = this->getPercorridos(false);
ListaParNoVisitado *visitados = this->getVisitados(false);
if(!origem->getElos()->empty())
this->buscarElosEmProfundidadeAux(*(origem->getElos()->begin()), origem, visitados, percorridos, func);
delete percorridos;
delete visitados;

} I tried calling this function like this : searchElEmProfundity(No*pointer) and gave error . What’s the right way to call her then ?

And it shouldn’t be void, right ? Because the intention of this function is to return a list of nodes that are "reachable" from the source.

  • If you’re doing the code, you don’t know, it gets more complicated for us. S syntax is about this: http://en.cppreference.com/w/cpp/utility/functional/function How to use it now depends on your code. You have not posted information indicating how it should be used.

1 answer

0

This notation std::function<bool(No*, No*, Elo*)>func indicates a pointer to a prototype function bool func(No*, No*, Elo*) which must be passed as a parameter in the function call buscarElosEmProfundidade.

You must do more or less like this:

// ...
// ...
// ...

// coloquei nomes genéricos na função e nos parâmetros porque não
// sei como serão usados, mas você deve colocar nomes explicativos
bool nomeFunc(No* no1, No* no2, Elo* elo)
{
   // ...
   // sua implementação
   // ...
}

// ...
// ...
// ...

No origem;

// ...
// ...
// ...

buscarElosEmProfundidade(&origem, nomeFunc);

// ...
// ...
// ...

P.S. code not tested.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.