On Sep 14, 3:16 pm, foice <franceschini.robe...@gmail.com> wrote:
why can't I make the same inline assignment for vectors?
float fp_values[] = { 0.1, 0.2 , 0.3, 0.4};
as for instance this
vector<float> v=(1.2, 3.3, 4.);
As others have mentioned, you can do that sort of thing in the
forthcoming C++ standard (C++0x). The correct syntax will be:
std::vector<float> v = {1.2f, 3.3f, 4.f};
I think the latest version of the GCC compiler already supports this
if you enable the experimental C++0x features.
any idea how to do that in one line and for arbitrary lenght of the
initialization?
In the current C++ standard (C++03), you can't do this in one line.
But if you can live with doing it in three lines, this is the way I do
it:
const float kVArray[] = {1.2f, 3.3f, 4.f};
const size_t kVArraySize = sizeof(kVArray) / sizeof(*kVArray);
std::vector<float> v(kVArray, kVArray + kVArraySize);