error: invalid use of void expression

2

In this code I skip the following error: invalid use of void expression. More precisely in return ciclo_Euleriano(g, g.getVertices().pop_front(), g.getVertices().pop_front()); and I do not know why it is.

bool ciclo_Euleriano(const Grafo<T> & g, T u, T first) { //u es el vertice
    bool found = false;
    if (!aristas.empty()) {
        list<typename Grafo<T>::Arco> adyacentes = g.getAdyacentes(u);
        for (typename list<typename Grafo<T>::Arco>::iterator it = adyacentes.begin(); it != adyacentes.end() && !found; it++) {
            if (Camino_no_Usado(u, it->getAdyacente(), aristas)) {
                addArista(camino, u, it->getAdyacente(), g.getCosto(u, *it));
                eliminar(u, *it, aristas);
                found = ciclo_Euleriano(g, *it, first);
                if (!found) {
                    addArista(aristas, u, *it, g.getCosto(u, *it));
                    camino.pop_back();
                }
            }
        }
    } else
        if (u == first)
            found = true;
    return found;
}

bool ciclo_Euleriano(const Grafo<T> & g) {
    list<typename Grafo<T>::Arco> aristas = g.getAristas();
    camino.clear();
    return ciclo_Euleriano(g, g.getVertices().pop_front(), g.getVertices().pop_front());
}

Here I leave the getVertices() :

list<T> getVertices() const {
    list<T> vertices;
    for (typename map<T, map<T, int> >::const_iterator itV = grafo.begin(); itV != grafo.end(); itV++)
        vertices.push_front(itV->first);
    return vertices;
}
    
asked by Guido Modarelli 09.07.2018 в 21:05
source

1 answer

3

The type void by definition is an incomplete type, which can not be completed. It can not be part of expressions or be instantiated.

You are calling the ciclo_Euleriano function by passing the result of calling two functions that return void .

Given that Grafo<T>::getVertices returns a std::list , we can see that the function pop_front returns void :

Surely what you wanted was to get the heads ( front ) call ciclo_Euleriano and then delete the head element:

bool ciclo_Euleriano(const Grafo<T> & g) {
    const auto &aristas = g.getAristas();
    auto v = g.getVertices().front();

    camino.clear();
    g.getVertices().pop_front();

    return ciclo_Euleriano(g, v, v);
}

As an additional note, your code would improve a lot in readability by using auto and some C ++ utilities:

list<T> getVertices() const {
    list<T> vertices;

    std::copy(grafo.begin(), grafo.end(), std::front_inserter(vertices));
    return vertices;
}
    
answered by 10.07.2018 / 08:37
source