Hi, Im trying to return a pointer of a struct i've made.
Code:
return (object);//<-- this dont work :/
This is my struct.
Code:
typedef struct DOBJECT{
var x,y,z;
}DOBJECT;
And this is my function.
Code:
DOBJECT* create_dobject(VECTOR* position){
DOBJECT* object; //only a temp object
object.x = position.x;
//...
return (object); // return DOBJECT*(object); <- this is not working too
}
DOBJECT* globobj = create_doject(nullvector);
Sorry for my bad english. Greetings Ralph.
Re: Return a struct pointer
[Re: Ralph]
#253954 02/27/0923:2102/27/0923:21
return(object); is correct, but this line is wrong: DOBJECT* object; This just defines a pointer and I think normally is should crash at the line object.x = position.x;
You have to allocate your object: DOBJECT* object = malloc(sizeof(DOBJECT));