Answer the question
In order to leave comments, you need to log in
What does ::value_type mean in the example?
Good evening. Tell me what it means in the example :: value_type and where can I get to know it better?
I so understood so it is possible to define own type.
template <typename T>
class Point
{
public:
typedef T value_type;
T x,y;
};
int main()
{
cout << "use of template classes" << endl;
Point<int> P = {1,2};
//Point<int>::value_type X = P.x; /// ?????
Answer the question
In order to leave comments, you need to log in
This is used in order to be able to get the template parameter from outside. Usually in order to have an abstract name for the type of stored elements, iterator types, and any types derived from template parameters.
It is this example that is unsuccessful, because value_type
you take again from an explicitly specified template. If you change the type to , P
for example Point<double>
, then the type X
will have to be changed.
Here's a better example:
typedef Point<int> MyPoint;
MyPoint P = {1, 2};
MyPoint::value_type X = P.x;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question