template <class T>
class Test
{
....
Test() {createTest();}
using value_type = T;
using class_type = Test<T>;
using iterator = Test<T>*;
....
....
}
template <class T>
void Test<T>::createTest() // How to use 'iterator' instead of Test<T>?
{
.......
}
OR it's fine if I use like that?
And if I have to use 'T' type in createTest, should I use just 'T'? or 'value_type'?
because if I use value_type, there is no 'T' word but I used template <class T>.
is it right thing?
// Ganado
Thank you for your answer, but I know value_type and T are the same.
What I meant..
I declared template <class T> in createTest function.
and if I use 'value_type' not 'T', you can't see 'T' as a type but you can see 'value_type'
even if I declared 'T' in function. is it fine?
I wonder if users can be confused.
Like this.
1 2 3 4 5 6 7 8 9 10
template <class T>
void Test<T>::createTest()
{
// both OK.
value_type temp;
T temp2;
// but if I use value_type, you can't see 'T' even if I declared template argument as 'T'
// What should I use them?
}
template <class T>
void Test<T>::createTest()
{
value_type you_can_use; // if i use value_type as a type
value_type this_type;
}
and this one
1 2 3 4 5 6
template <class T>
void Test<T>::createTest()
{
T you_can_use; // if i use T as a type
T this_type;
}
I know both codes work the same.
but what I said "see" meaning is just about readability.
If I use value_type as type, a user or whoever can say "where is T used?"
I just want to know which one other people will use if this situation.
I don't speak English well.. so I can't tell you what I mean detail ...
I hope you will get it.. thank you!
T and value_type are both names for the same type.
Hopefully you selected "value_type" to be meaningful within the code. It is an alias to the formal type argument to the template. It hides the details of the class implementation from the user so the user does not understand how T fits in.
You can have a class where you have a type that might be something like iterator<BaseClass<T>::CollectionClass>> or something obscure like that. You can create an alias to this with using MyIterator = iterator<BaseClass<T>::CollectionClass>>;
It is so much easier to just deal with a MyIterator type than the ugly mess that it hides.