Skip to main content
GameDev.net gamedev.net
🔒 Locked

getting array/pointer out of function

Started by pixienick Aug 11, 2004 at 8:42 AM 4 replies 700+ views
Original Post
pixienick
pixienick
I got a function which builds a massive buffer of data in an array. I just cant seem to get this array out of the function like either; void function(float *data) { data = new float[lots]; for(i) { data = something } } or float *function() { data = new float[lots]; for(i) { data = something } return data; } the data is never filled outside/after the function, know what i mean? any suggestions much appreciated cheers
Kippesoep
Kippesoep
Either use the return value, or use a pointer reference:

void function (char *&data){  data = new char [1024];}
Kippesoep
pixienick
pixienick
Nice one Kippesoep, i never seen such a combo before (&*) - works a treat!
snk_kid
snk_kid
Quote:
Original post by pixienick
Nice one Kippesoep, i never seen such a combo before (&*) - works a treat!


Think about it pointers are just variables aswell so it's still pass by value except your making a copy of address instead of the instances it refers to

because you wont to modify the pointer passed in you need to either use pointer to a pointer or a reference to a pointer, references are better because no copy is made what gets passed in is what will actually be used.
pixienick
pixienick
tis all makes perfect sense once you get it working but intricacies like that can hold one up for hours when you dont know!
(or maybe thats just me)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.