Well I’d like to do this,
“…since vt is a vector allocated on the stack within Stl_To_Igraph_vector_ptr_t (i.e. you just declared it as a local variable and did not allocate it using malloc), it will cease to exist as soon as the function returns. You store a pointer to vt in your igraph_vector_ptr_t, but that pointer becomes invalid when you exit from the function, that’s why you are getting an error later. You have to make vt an igraph_vector_ptr_t, and use malloc to allocate it if you want it to outlive the conversion function.” by Tamas
and it was posted in Using std::vector with Igraph, I don’t know how to fill the vector v en the next code,
#include <igraph.h>
#include <stdlib.h>
int print_vector(igraph_vector_t *v) {
long int i, l=igraph_vector_size(v);
for (i=0; i<l; i++) {
printf(" %li", (long int) VECTOR(*v)[i]);
}
printf("\n");
}
int main() {
igraph_vector_ptr_t vecs;
long int i;
igraph_vector_ptr_init(&vecs, 3);
for (i=0; i<igraph_vector_ptr_size(&vecs); i++) {
VECTOR(vecs)[i] = calloc(1, sizeof(igraph_vector_t));
igraph_vector_init( (igraph_vector_t*)VECTOR(vecs)[i], 10);
}
igraph_vector_t *v;
v=(igraph_vector_t*)malloc(sizeof(igraph_vector_t));
igraph_vector_init(v, 10);
VECTOR(v)[0]=1;//-------??????????
igraph_vector_ptr_set(&vecs,0,v);
for (i=0; i<igraph_vector_ptr_size(&vecs); i++) {
print_vector( (igraph_vector_t*)VECTOR(vecs)[i]);
igraph_vector_destroy( (igraph_vector_t*)VECTOR(vecs)[i]);
free(VECTOR(vecs)[i]);
}
igraph_vector_ptr_destroy(&vecs);
igraph_vector_destroy(v);
return 0;
}
vis a pointer, and it looks likeVECTORexpects its argument to be a value. So changeVECTOR(v)toVECTOR(*v).