Hey this is more of a theoretical question, and I can't put code up for academic dishonesty reasons.
I have an assigned project where I have a tree data structure. The nodes are a class, the tree is a class, and a special instance of the tree exists in a class that inherits from the class.
In thee special tree, we are expected to look through the tree and find values. The nodes have functions that return left and right pointers and data, but the data and the pointers are const. Also the entire function is const, making everything in the tree const. If I want to start at the root, I must make a const node pointer and set it equal to this->root. I would usually just have a loop that uses a single pointer to travel down until I find the item, but everything is const and returns constants, so I can't change my pointer once I have made it.
Is there something simple I should be using in order to go down through the tree? I can get the left child of the node and the right child of the node but the pointers to the children are const, so I would need a new pointer to receive the values they return. That is where the loop stops working.
Sorry I cannot post code, but I really have no idea what to do.
It sounds like you are confusing a pointer that is const with a pointer that points to something that is const.
1 2 3 4
const Node* p; // A non-const pointer pointing to a const Node.
Node const* p; // Same as above.
Node* const p; // A const pointer pointing to a non-const Node.
Node const* const p; // A const pointer pointing to a const Node.