用G++编译C++代码报错:In instantiation of 'struct std::iterator_traits'

… In instantiation of ‘struct std::iterator_traits’:
required from '_OI std::__copy_move_a(_II, _II, _OI) …
required from '_OI std::__copy_move_a2(_II, _II, _OI) …
required from '_OI std::copy(_II, _II, _OI) …
error: ‘xxx’ is not a class, struct, or union type
      typedef typename _Iterator::iterator_category iterator_category;
error: ‘xxx’ is not a class, struct, or union type
      typedef typename _Iterator::value_type value_type;
error: ‘xxx’ is not a class, struct, or union type
      typedef typename _Iterator::difference_type difference_type;
error: ‘xxx’ is not a class, struct, or union type
      typedef typename _Iterator::pointer pointer;
error: ‘xxx’ is not a class, struct, or union type
      typedef typename _Iterator::reference reference;

检查编译单元内的std相关代码的用法,尤其是std函数的参数是否正确。

例如:
char source[] = {1, 2, 3, 4, 5};
std::vector dest;
std::copy(source[0], source[5], std::back_inserter(dest));
std::copy前两个参数就会导致编译出这种错误。

你可能感兴趣的:(C/C++)