Iterator example

Why we have used two template class in the example of the video? Can’t we make only one template class and then also can pass the values as ForwardIterator Types. Please explain?

This is for the type of container we are using like, vector array linked list etc…
Whereas T is the data type of that container, which can be int float char

now you are saying that can’t we make a class in which ForwardIterator and T are included(expecting this is your question) ?
Yes we can do that you can read for that from hereLink
Also if this wasn’t your doubt, please elaborate it.

Thanks for explanation, but the question was like if we don’t include template class ForwardIterator and then can’t we accept the parameter ForwardIterator start in the search function and use it to search key in different datatypes.

Yes you can do that , but that won’t be generic.
Suppose if you are doing it for integer array. The ForwardIterator will be of int data type? As you haven’t made a template for that. You will return int in that case, Return type of function becomes int. Whereas if you have linked list, then instead of int , you have to return node. So, Return type of function has to be node. for that if your function is not generic. Then you have to write code for linked list containers again. That’s why bhaiya declared 2 different templates, one used to store container and other it’s data type.
Hope this will solve your query.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.