As you can see, from my output results, the address of this changed during execution for me, I thought I could make use of Pointer comparison for achieving a Tree system without having a child list inside Node and I want to be able to compare parent for each element inside a nodo list for further functionality. but the main issue for it is pointer address changing, can anyone help me understand what I'm missing.
struct Nodo{
Nodo* parent=0;
const char* identity;
Component* component;
Nodo()=default;
Nodo(const char* uid){
identity=uid;
}
Nodo(Nodo* ptr,const char* uid){
parent=ptr;
identity=uid;
std::cout << "\n Address given to " << uid << " " << ptr <<std::endl;
}
void Add(const char* uid,std::vector<Nodo>& objects){
std::cout << "\n Add call in " << identity << " address sent "<< this <<std::endl;
objects.emplace_back(Nodo(this,uid));
}
void GrapthUI(std::vector<Nodo>& nodes){
ImGui::PushID(this);
if(ImGui::TreeNode(identity)){
ImGui::TreePop();
ImGui::Indent();
for(int indx=0; indx<nodes.size(); indx++){
if(&nodes[indx]!=this){
if(nodes[indx].parent==this){
nodes[indx].GrapthUI(nodes);
}
}
}
ImGui::Unindent();
}
ImGui::PopID();
}
}
std::vector<Nodo> node;
Main(){//in c++ file.
node.emplace_back(Nodo("root"));
node[0].Add("Airplane",node);
node[0].Add("Ball",node);
node[1].Add("Car",node);
}
Output:
Add call in [ root ] address sent 0C8FCF88
Address given to [ Airplane ] 0C8FCF88
Add call in [ root ] address sent 0C920C68
Address given to [ Ball ] 0C920C68
Add call in [ Airplane ] address sent 0C916DE4
Address given to [ Car ] 0C916DE4
I expected the parent pointer for Airplane and Ball to have the same address [0C8FCF88] of Root but It's different. I saw a similar post to this here with the same name but it doesn't help me nor is concerning exactly my issue.