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?
Copyright © 2021 Jogjafile Inc.
You can read
typedef typename std::vector::size_type size_typelike this:typedeftypename std::vector::size_typesize_type, just liketypedef __int64 INT64.Why we need
typenamebeforcestd::vector::size_type? It just tells the compiler thatstd::vector::size_typeis a type not a normal class member. It's used for disambiguation.But I think maybe some compiler can auto detect
std::vector::size_typeis a type.So,
typedefjust creates an alias for an existing type, andtypenametells the compile thatstd::vector::size_typeis a type not a normal class member.