So this is my problem: as the title suggests, I have a Labyrinth class that contains two binary trees made of two different kinds of structs that represent different kinds of rooms. The names are in spanish, so Arbol means tree, Laberinto is the labyrinth class and Sala1 and Sala2 are the room structs (and Llave, in case you wonder, means key, but that's not relevant to my question).

struct Sala1 {
    int id;
    Llave cr_i;
    Llave cr_d;
    int fno_fix_i;
    int fno_fix_d;
    int fno_i;
    int fno_d;

struct Sala2 {
    int id;
    Llave cr;

class Laberinto
    Arbol<Sala1> a1;
    Arbol<Sala2> a2; 

/* functions, public, etc */

So my problem is this next piece of code won't work. In case it's hard to guess, x.raiz() obtains the root of tree x. This is a private function by the way.

void Laberinto::reset_contadores (Arbol<Sala1>& x){
    x.raiz().fno_i = x.raiz().fno_fix_i;
    x.raiz().fno_d = x.raiz().fno_fix_d;
/* rest of code, which calls the same function on the rest of the tree */

edit: The public function that calls it looks like this:

void Laberinto::simular_partida (Cjt_Jugador& c, Resultados& r, int N){
    reset_contadores (a1);
    /* rest of the function */

It's just not copying fno_fix_i to fno_i (nor fno_fix_d to fno_d) (checked by printing on screen). I tried creating an auxiliary Sala1 object inside the function and do the same thing to it, and it worked without a problem.

edit : It also won't change it if I try to do ++x.raiz().fno_i, of course. The thing that weirds me out the most is that I can read this tree and set values for fno_i and fno_d in the reading function without a problem, it just won't let me do it here.

What am I missing here?

Ps. Thanks for going through the trouble of reading code with lots of spanish in it, I hope you can understand. If you need anything more to help me with this (be it translations or more code), I'll be more than glad to post it.

Edited by alllucky7s: n/a

6 Years
Discussion Span
Last Post by alllucky7s

Finally solved it creating an auxiliary room and using a function that we call 'planting' in spanish, which uses that room and the two children of x to create a new x... I don't like it, but it works.

I'll mark the thread as solved because it works, but if someone knows why my original solution isn't working, they're free to post.


Edited by alllucky7s: n/a


Finally understood why it didn't work. root() (or raiz() in my code) is a function that returns a copy of said root, so if you modify it you're modifying the copy, not the actual object.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.