+ 1

Why my variable class doesn't contain its value?

I'm trying to figure out why my variable "treeIndice" doesn't have its information to be used in other functions. Here is the code: https://code.sololearn.com/ch5A7RLYE5dq/#cpp In another words, I have a private variable called Tree<Index> treeIndice; (line 11), and, the function void ElectronicEmail::loadIndexToTree() (line 67) inserts some information to the treeIndice (line 108). Inside this function, "treeIndice" has its content, but when I try to use "treeIndice" inside the function void ElectronicEmail::findIndex(const std::string &fileName, int& id), treeIndice is empty (line 142). Why "treeIndice" is empty if in the other function ElectronicEmail::loadIndexToTree(), I inserted some content to the variable "treeIndice". I thought that inserting some content to that variable in a function, I would have its value ready to use to another functions. I don't know how to solve this, how to save its value and use it in another function. I tried to use setters and getters (29, 43) but it didn't work. Note: Tree class is a class made by me, I tried to overload the operator = but I couldn't make it work (maybe that's why my setters and getters doesn't work?, lines 151-193)

29th Nov 2019, 4:46 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
3 Respostas
+ 3
Hola Eduardo Perez Regin It is a bit hard to debug your code since it is incomplete. I cannot tell how you implemented your Tree class. But from your description and the code you included I think the problem is in the constructor of the class EletronicMail. I could help more with the complete code.
30th Nov 2019, 11:26 AM
Mark
0
Mark thx for checking my problem, actually I solved it yesterday at night, and indeed, the code I posted is not enough to solve the problem (because the problem was in another part and I didn't know that). You are almost right, the problem was in the constructor (in another class) where I have an object of ElectronicEmail to call those functions. Basically, I had this. Search::Search() { // Problem was here, the tree content only exist while this object lives in the constructor. ElectronicEmail email; email.loadToTreeIndex(); } I only created an ElectronicEmail object as private variable for my class Search and that's it, that was the solution, not having a local object in my constructor.
30th Nov 2019, 4:08 PM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
0
Hola Eduardo Perez Regin I am glad you solve the problem. Thanks for sharing the way you solved it. Hasta el prossimo problema :)
30th Nov 2019, 5:31 PM
Mark