May 19th, 2011, 01:38 PM
function parameter by reference
I have the following function, I use it to read tags from a xml file. It returns true when it is able to read and false when something fails. I also update the values of "node_start" and "node_end" so I can keep track of the values read from outside. Here is the code:
The problem I'm having is the values of node_start and node_end that aren't being passed as reference, but by value - they do not update their values outside the function. Here is where I call the function:
bool getNode(char *begin, char *end, const char *name, char *node_start, char *node_end)
string starttag = "<",endtag = "<";
starttag += name;
starttag += ">";
endtag += "/";endtag += name;endtag += ">";
char *_node_start = strstr(begin,starttag.c_str());
if((_node_start == NULL)||(_node_start >= end))return false;
char *_node_end = strstr(_node_start+starttag.length(),endtag.c_str());
if((_node_end == NULL)||(_node_end >= end))return false;
node_start = _node_start;
node_end = _node_end + endtag.length();
I'm sure I'm missing something kind of obvious, but I just can't see it. Can you help me?
char *node_start = NULL,*node_end = NULL,*begin = &(*beginFile),*end = &(*endFile);
//process information (I need node_start and node_end here)
Thanks in advance
May 19th, 2011, 01:56 PM
Re: function parameter by reference
If you need to change the pointer itself, declare it as you would any other reference.
getNode(char*& begin ...
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!