I have read the book named C++ primer and I don't understand the following code:
typedef typename std::vector<int>::size_type size_type;
Could you help me explain the use of typename here?
I have read the book named C++ primer and I don't understand the following code:
typedef typename std::vector<int>::size_type size_type;
Could you help me explain the use of typename here?
You can read typedef typename std::vector::size_type size_type like this:
typedef typename std::vector::size_type size_type, just like typedef __int64 INT64.
Why we need typename beforce std::vector::size_type? It just tells the compiler that std::vector::size_type is a type not a normal class member. It's used for disambiguation.
But I think maybe some compiler can auto detect std::vector::size_type is a type.
So, typedef just creates an alias for an existing type, and typename tells the compile that std::vector::size_type is a type not a normal class member.