I am trying to return a pointer to my structure from a function:
dbentry* FileReader::parseTrack(int32_t size, char *buffer) {
dbentry* track;
int cursor = 0;
//parse relevant parts
track.title = this->getFieldForMarker(cursor, size, "tsng" , buffer);
return track;
}
setting title is obviously not working but i don’t know what to do, also how would i read a value from the pointer, ive tried some casting but nothing seems to work, most of what i found i couldn’t figure out how to apply, or it was for C.
You didn’t allocate the structure memory, thus you’re accessing and returning no memory address. You would need something like this:
Note that you have to return the structure pointer, so you don’t want to dereference the pointer in its return, so just use
return track;instead ofreturn *track;.The reason for this is that track is already a pointer. You would return the pointer of a pointer in your original solution.
So you would use the function like this: