If I have a class like:
class Node
{
string id;
const Node next;
}
How do I find, say, the id of the last Node in the linked list?
string lastID(const Node node)
{
???
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume that your problem is that you need to loop but can’t reset your variable, because it’s const? If you want to have an object which refers to a const object but is re-assignable itself (i.e. it’s tail-const), then use
std.typecons.Rebindable. In this case, that gives you:I must say that I find it a bit odd though that you don’t just ask about how to have a reference to a const object where the reference isn’t const itself, since that’s all I can see that you’re really asking here, given how straightforward the loop itself is. As it stands, your question is a bit too much along the lines of asking someone to write your code for you rather than asking a question.