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

本文详细解析了使用std::copy函数时遇到的编译错误,错误源于参数类型不被识别为类、结构体或联合类型。文章通过具体代码示例,指导如何正确使用std函数,避免此类编译错误。

… 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前两个参数就会导致编译出这种错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值