有人能说出使用数组向量的正确方法是什么?
我声明了一个数组(vector<float[4]>)的向量,但error: conversion from 'int' to non-scalar type 'float [4]' requested在尝试时得到resize了.出了什么问题?
在C++ 11中,有两个版本std::vector::resize():
void resize( size_type count );
void resize( size_type count, const value_type& value);
Run Code Online (Sandbox Code Playgroud)
我理解(正如对该问题的答案之一的评论之一所建议的),第一个要求value_type是默认可构造的,而第二个要求它是可复制构造的.但是,(gcc 4.7.0)
using namespace std;
typedef int block[4];
vector<block> A;
static_assert(is_default_constructible<block>::value,";-("); // does not fire
A.resize(100); // compiler error
Run Code Online (Sandbox Code Playgroud)
所以要么我的理解是错误的,要么gcc是错误的.哪一个?
我需要在包含wchar_t的c-string的C++程序向量中使用.我试着这样做:
using std::vector;
vector<wchar_t[SIZE]> string_list(100);
Run Code Online (Sandbox Code Playgroud)
但我得到包含以下单词的大错误输出:
error: functional cast to array type «std::vector<wchar_t [512]>::value_type {aka wchar_t [512]}»
Run Code Online (Sandbox Code Playgroud)
我做错了什么?为什么我会收到这样的错误