正确的方法与阵列的矢量工作 [英] Correct way to work with vector of arrays
问题描述
有人能告诉什么是阵列的矢量工作的正确方法是什么?
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屋!