Created class not passing by reference

closed account (oEwqX9L8)
I have a couple created class that I can't get to pass by reference.

 
 string parseTokens(queue<token>& foundTokens, datalogProgram& _program);


Then I call it later

1
2
datalogProgram _program;
cout << parseTokens(foundTokens, _program)


datalogProgram has a toString() function. I used cout becuase I had to print the _program infor from within the function. If I try to print it from my main where parseTokens() is called, _program is empty.

Can anyone help me out?
Are you saying cout << _program.toString(); does not output anything if you put it after the function call but it does if you put it inside the function?
closed account (oEwqX9L8)
Right! At the end of the parseTokens function I return a string containing _program.toString() and it works. But if I try and call _program.toString() right after cout << parseTokens(foundTokens, _program) in the main it outputs nothing (an empty datalogProgram object).
Last edited on
The code that you have posted doesn't give any hints as to why that would happen. If the whole code is too long to post here you could try to remove everything that is irrelevant to the problem. Aim for a minimal program that can still be compiled with the problem that you want to show. In the process of doing so there is a great chance that you will find the problem yourself. Otherwise you can post it here and we'll have a look.
Last edited on
closed account (oEwqX9L8)
Think I figured it out, thanks for the advice and feedback!
Topic archived. No new replies allowed.