Reputation: 21
Here I have a piece of code which is a part of a class named Sistema (all the declarations are in a separate file). The first function is supposed to call the next one, which is a recursive function that reads some tree (Arbre is a custom implementation of tree).
While running the program the output shows the "entering function" line, just before the funcion call, but I never get "new node" line. So my program gets lost somewhere between the funcion call and the function itself, even before any recursive call. I never got a problem like this before. Any clue about what is happenig?
Here is the code:
#include "Sistema.hpp"
............
list<int> Sistema::proc_peticion(int pelicula, int tiempo, int tamano){
list<int> srv;
Arbre<int> arb = estructura;
bool unidad_tmp = false;
int dist = 0, bw = 0;
cout << "entering function" << endl;
camino(srv, arb, pelicula, tiempo, tamano, unidad_tmp, dist, bw);
return srv;
}
............
void Sistema::camino(list<int>& srv, Arbre<int>& arb, const int& pel, const int& tmp, const int& size, bool& unidad_tmp, int& dist, int& bw){
cout << "new node ";
if (not arb.es_buit()){
..................
}
}
I tried to leave only the parts of the code that might be useful, to make it more readable. Let me know if you need something more.
Thanks in advance
Upvotes: 2
Views: 137
Reputation: 52659
You should write an endl inside the camino function, when you write to a file in C/C++, the data is not necessarily written to the file, but sits in a memory buffer until its filled up or is explicitly written (flushed) to disk.
What's probably happening here is the write is happening, the program continues and hangs inside the function. If you don't want to write an endl (which performs the write) you can call cout.flush()
afterwards.
Upvotes: 4