… In instantiation of ‘struct std::iterator_traits<xxx>’:
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前两个参数就会导致编译出这种错误。
本文详细解析了使用std::copy函数时遇到的编译错误,错误源于参数类型不被识别为类、结构体或联合类型。文章通过具体代码示例,指导如何正确使用std函数,避免此类编译错误。

2638

被折叠的 条评论
为什么被折叠?



