正确的方法与阵列的矢量工作 [英] Correct way to work with vector of arrays

查看:114
本文介绍了正确的方法与阵列的矢量工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉什么是阵列的矢量工作的正确方法是什么?

Could someone tell what is the correct way to work with a vector of arrays?

我宣布阵列(矢量<浮动[4]> )的载体,但得到了错误:从'诠释'转换到非标量型浮动[4]试图时调整它要求。这是怎么回事了?

I declared a vector of arrays (vector<float[4]>) but got error: conversion from 'int' to non-scalar type 'float [4]' requested when trying to resize it. What is going wrong?

推荐答案

您不能存储在矢量或任何其他容器阵列。类型的元素的要被存储在一个容器(称为容器的值类型的)必须既拷贝构造和可分配。数组是没有。

You cannot store arrays in a vector or any other container. The type of the elements to be stored in a container (called the container's value type) must be both copy constructible and assignable. Arrays are neither.

您可以,但是,使用阵列类模板,像升压,TR1中提供的,和C ++ 0x中:

You can, however, use an array class template, like the one provided by Boost, TR1, and C++0x:

std::vector<std::array<double, 4> >

(你要替换的std ::阵列的std :: tr1 ::阵列使用包括在C ++ TR1模板,或的boost ::阵列使用的从Boost库模板或者,您也可以编写自己的;它很简单)

(You'll want to replace std::array with std::tr1::array to use the template included in C++ TR1, or boost::array to use the template from the Boost libraries. Alternatively, you can write your own; it's quite straightforward.)

这篇关于正确的方法与阵列的矢量工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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