skyeagle
skyeagle

Reputation: 7325

assign to std:vector from a structure containing an array

I am trying to assign data from a struct to a std::vector

Here is the code

struct myArray
{
   double * data;
   size_t   len;
};


typedef std::vector<double>  DoubleVect;


DoubleVect myvect;
MyArray myarr;

// code to initialize alloc and populate the MyArray variable
// ....


myvect.assign(&myarr.data, &myarr.data + myarr.len);  // compiler barfs here ...

Any idea why? and how may I fix this?

Upvotes: 0

Views: 446

Answers (1)

sellibitze
sellibitze

Reputation: 28087

Yes. Get rid of the address operator and it will be fine. Taking the address of the data member data gives you an expression of type double**. This is certainly not what you want.

Upvotes: 4

Related Questions