Topic: Problem with C++0x and vector.resize
Author: Syron <mr.syron@googlemail.com>
Date: Fri, 2 Jul 2010 16:28:56 CST Raw View
I have code like this, using gcc 4.5 and --std=c++0x:
typedef uint16_t BasicSample;
typedef BasicSample BasicSampleFrame[2];
void foo() {
std::vector<BasicSampleFrame> vec;
...
// here it sais: error: conversion from int to non-scalar type
short int [2] requested
vec.resize(bar);
// then here: error: no matching function for call to
std::vector<short int [2]>::resize(const size_t&, <brace-enclosed
initializer list>)
// /usr/include/c++/4.5/bits/stl_vector.h:553:7: note: candidate is:
\
// void std::vector<_Tp, _Alloc>::resize(std::vector::size_type,
value_type) \
// [with _Tp = short int [2], _Alloc = std::allocator<short int
[2]>, \
// std::vector::size_type = long unsigned int, value_type = short
int [2]]
vec.resize(bar, {0,0});
// for the line above, when I use "static const BasicSampleFrame
f{0,0};" instead of the {0,0},
// the error remains
}
any suggestions about that? I know that I could use erase and
push_back, but this error is annoying, and I want to know if I am
doing something wrong.
btw, std::initializer_list also didn't help.
-- Syron
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Mathias Gaunard <loufoque@gmail.com>
Date: Sun, 4 Jul 2010 14:36:26 CST Raw View
On Jul 2, 11:28 pm, Syron <mr.sy...@googlemail.com> wrote:
> // then here: error: no matching function for call to
> std::vector<short int [2]>::resize(const size_t&, <brace-enclosed
> initializer list>)
You may not put arrays in a container, are they are not
CopyConstructible nor Assignable.
Use std::array/boost::array instead.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Syron <mr.syron@googlemail.com>
Date: Tue, 6 Jul 2010 02:27:33 CST Raw View
Am 04.07.2010 22:36, schrieb Mathias Gaunard:
>
> You may not put arrays in a container, are they are not
> CopyConstructible nor Assignable.
> Use std::array/boost::array instead.
Thanks, I figured it out myself... I decided to replace my
BasicSampleFrame by an unaligned/packed struct, and it works.
-- Syron
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]