function parameter by reference
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: function parameter by reference

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    24

    Question function parameter by reference

    Hi everyone,
    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:
    Code:
    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();
    	return true;
    }
    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:
    Code:
    char *node_start = NULL,*node_end = NULL,*begin = &(*beginFile),*end = &(*endFile);
    while(getNode(begin,end,"class",node_start,node_end))
    	{
    		//process information (I need node_start and node_end here)
    	}
    I'm sure I'm missing something kind of obvious, but I just can't see it. Can you help me?

    Thanks in advance

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,050

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center