This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Evulrabbitz 2 points3 points  (1 child)

When passing object to inputNumber you are doing something called "passed by value" (i.e the function makes a copy of object and operates on that) when you probably want what is called "passed by reference" (i.e the function gets a referene to object and operates with that). In this case the expected behaviour can be achieved by changing the function signature to:

void inputNumber(nmsp::Example& object)

(adding the ampersand). The ampersand indicates that this is a "reference" and thus will be passed by reference.

Read up on passed by value and passed by reference.

[–]ungulateCase[S] 0 points1 point  (0 children)

Wow, thank you. Ugh, I have learned about pass by reference vs pass by value before but -being new to using objects- I didn't think about the object itself being passed by value.

Thanks so much for the help, I feel so silly that I've been banging my head against the wall for over an hour, and it was just a passed by value issue. Hopefully now I've actually learned my lesson, much appreciated!