I need help with functions with an assignment

Pages: 12
I'm still getting this error:

/tmp/cc9JkeH6.o: In function `main':
main.cpp:(.text+0x1c): undefined reference to `getInfo(bool, int, int)'
collect2: error: ld returned 1 exit status


It mentions my reference is undefined but I'm sure I got it right. The comment you made about having to add the reference. How do I go about doing that. Because isn't line 15 where I'm doing that?
Last edited on
Line 7 in your code, the getInfo function prototype. Does it read:

void getInfo(bool senior, int months, int personal);

or something like

void getInfo(bool& senior, int& months, int& personal);

Your function definition starting at line 42 is this:

void getInfo(bool &senior, int &months, int &personal)

The two "signatures" must be the same. The last code you posted didn't have the references in the function declaration.

In the context of a function parameter "&" says the parameter is a reference. It transfers the actual variable into the function instead of making a local copy. So any changes made to the variable in the function are retained back where you called the function in main().

It looks to me you need a "refresher" on references.

https://www.learncpp.com/cpp-tutorial/611-references/

https://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/

Topic archived. No new replies allowed.
Pages: 12