include files in C++

In Item 42: Understand the two meanings of typename of Effective C++, there is the following code. I have spent a lot of time figuring out that the code can't be compiled if iterator is not included

 

#include <type_traits>
#include <iterator>

template<typename IterT>
void workWithIterator(IterT iter) {
  typedef typename std::iterator_traits<IterT>::value_type value_type;
  value_type temp(*iter); 
}

int main(int argc, const char *argv[]) {
  return 0;
}
 

 

The reason is that IterT will be expand to some iterator.

你可能感兴趣的:(C++,c,C#)