错误:不能通过`...`传递非trivially可复制类型的对象 [英] error: cannot pass objects of non-trivially-copyable type through `...`

查看:1859
本文介绍了错误:不能通过`...`传递非trivially可复制类型的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单元,它有

std::is_trivial<unit>::value; // true
std::is_trivially_copyable<unit>::value; // true (on compilers which have this trait)

我想传递的是作为元组,例如

I'd like to pass are vectors of unit as a tuple, e.g.

using geodeticTuple = std::tuple<unit, unit, unit>;

我需要这些向量可以传递到使用不同类型参数的转换函数,例如

I need these vectors to be passable into conversion functions who use different types of arguments, e.g.

someOtherType convert(const geodeticTuple& point,const geodeticTuple& origin)

someOtherType convert(const geodeticTuple& point,...)

好的,但是用gcc-4.9.3,我得到的错误:

using MSVC2015, this works totally fine, but with gcc-4.9.3, I'm getting the error:


错误:不能传递非trivially类型 const geodeticTuple {aka const struct std :: tuple< unit,unit,unit>} 通过 ...

,因为gcc-4.9.3不支持 is_trivially_xxx 样式类型

and since gcc-4.9.3 doesn't support the is_trivially_xxx style type-traits, I'm having trouble understanding why this is failing.

是一个简单的类型的元组不可以复制吗?

Is a tuple of trivial types not trivially copyable?

推荐答案

tuple 的复制/移动赋值运算符需要对引用类型进行特殊处理,一般情况下。

tuple's copy/move assignment operators require special handling for reference types, so they must be user-provided in the general case.

由于标准不需要微不足道的可复制性,这是一个QoI问题,无论实现者是否提供额外的长度提供保证(这将需要添加额外专业)。

Since the standard doesn't require trivial copyability, it's a QoI issue whether the implementers go to the extra length of providing that guarantee (which would require adding additional specializations).

这篇关于错误:不能通过`...`传递非trivially可复制类型的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆