c++ - null pointer is returned -
i have test defined this:
classname filehandle; classname1* data; //i want function define later filehandle.getdata(data); //this null after call isn't in function calls //why isn't pointer defined method called? how fix?
the function calls looks this:
void classname::getdata(classname1* data) { char * buf = "lots of data"; data = new classname1(buf, sizeof(buf)); //it's in there }
i'm sure it's issue understanding of pointers , references. ideas i'm doing wrong here? why isn't value of data still defined when returns test?
i saw examples of pointers , function calls here i'm having trouble finding example this. this seems might similar too, i'm still confused.
pass pointer reference &
:
void classname::getdata(classname1* &data2)
for clarity renamed variables data1
, data2
can see different. when passing reference same, otherwise address stored in local pointer data2
destroyed after getdata
function exits , null address stored in input data1
remains unaltered.
the call syntax remains same:
filehandle.getdata(data1);
Comments
Post a Comment