Reputation: 7325
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
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