正确的方法与阵列的矢量工作

问题描述:

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

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.)