I would like to find the values in the templateed concatenation list using the recursive function (recursive method).What I'm worried about is the temporary argument of the re-function.A common solution is to pass the head of the concatenated list in the call of the function of the restart.However, what I want to do this time is to give only the value I want to find when I call a function outside that function.The following code will cause an error in the findValue function.Here's why:Invalid use of non-static data member 'head'
In other words, the head is a non-static member, so it cannot be used as a temporary argument.
Since it is templateized, I would like to find out if there is a value for various data types, and return true, if not false.I thought I could do it if I could set the currentLink as head, a temporary argument for findValue, but I got an error saying that I couldn't do this.
If you are familiar with this area, please take care of me.
Note: The professor gave me a hint.By creating a new method in the private of the list class and calling it within the findValue provisional argument, currentLink=head is set, and it seems that this re-function works.In other words, I think it will work if we can create a method called within this findValue temporary argument.If you understand, please take care of me.c++
We have found a solution.What I was trying to do seemed a little off the mark.
Define recFindValue in private, similar to findValue above.The recFindValue provisional argument sets the value to look for, the value and the link to find the value, and the currentLink.The default value of the argument is mentioned in the comment, but the default value of the argument is not used.The others are the same as the findValue above.
What the actual findValue does is just take the value you look for and pass it to recFindValue, plus the head at the beginning of the consolidated list.That is, call recFindValue.
Then return the result returned from recFindValue
In other words, this is the code.Only the periphery of the unusual part will be displayed here.
The hint you gave me is a bit subtle if I were to think of recursion as the subject.
In terms of tips, C++ has the following features that allow you to create functions with the same name with different parameters:
How to specify a member variable as the default argument
It's different from recursive, but it's calling a function with the same name.
This article will be helpful if you want to discuss the subject of recursive.
I want to set the default value to the pointer of the structure in the argument
Understanding the Default Arguments for the C++ Class
If the default argument is set to a value that is not valid, then use the initial value that you want to use.
© 2023 OneMinuteCode. All rights reserved.