I have a strange behavior with the following code using `Eigen` library.

If I assign the pointer to `DoubleListCg->doubles`, then the value I get for the `DoubleListCg->doubles[i]` is wrong. But if I assign the element one by one, then the value I get for the pointer array above is correct. Why?

This is my code below:

```
#define DllExport   __declspec( dllexport ) 

#include "stdafx.h"
#define EIGEN_USE_MKL_ALL
#include <iostream>
#include "Eigen/Dense"
#include "Eigen/src/Core/util/MKL_support.h"
#include <Eigen/Sparse>
#include <Eigen/Eigenvalues>
#include <vector>
#include <Eigen/PardisoSupport>
using namespace std;
using namespace Eigen;

extern "C" struct DllExport DoubleListCg
{
    int num_points;
    double* doubles;
};

// working
void DoubleList(VectorXd vector, DoubleListCg *dListPtr)
{
    dListPtr->num_points = vector.size();
   dListPtr->doubles= (double*) malloc ( dListPtr->num_points*sizeof(double));
   for (int i = 0; i < vector.size(); i++)
   {
       dListPtr->doubles[i]=vector[i];
   }     

}

//not working
void DoubleList2(VectorXd vector, DoubleListCg *dList)
{
    dList->num_points = vector.size();
    dList->doubles =vector.data();

}

void VectorConvert()
{
    VectorXd vector(3);
    vector<<1,2,3;

    DoubleListCg dList;
    DoubleList(vector, &dList);  //this works; the dList gets the right values at first element

    DoubleListCg dList2;
    DoubleList2(vector, &dList2)  //this doesn't work; the dList2 gets the wrong values at first element

}

```

It must be something really elementary that I hang up. 

**Related question:** Is there anyway that I can point `dList->doubles` at the `vector.data()`? I don't want to copy everything over and over again