So on one of my project programs I am having an issue trying to get rid of this error:
main.cpp:(.text+0xc9): undefined reference to `void readCin<int>(int&)'
Instead of posting my entire program here I made a smaller one that wound up creating the same problem to see if anyone can help. I'm sure it's some beginning syntax/#include thing I'm forgetting but here it is anyway:
templates cannot be defined in a separate source file like that. You're getting this error for the same reason you get an error if you try to put the readCin prototype in a header file.
In order for functions to be linked, they must be instantiated. Function templates are not instantiated until they're called.
So basically:
-) main_functs does not instantiate readCin, it simply defines the template.
-) main.cpp is requiring that readCin<int> and readCin<char> be instantiated
-) main.cpp can't instantiate them itself because it doesn't see the template body
-) main_functs could instantiate them, but it doesn't know that it needs to, so it doesn't.
The solution here is to put the readCin body either in main.cpp where the prototype is, or move it and the prototype to a header file and #include that from main.cpp.
Either way, the entire function body must be in every cpp file that uses it. That's just how templates work.
"main_fucts.cpp" should probably be "main_fucts.h" and then instead of the template declaration of readCin() before main() you should have #include "main_fucts.h". Also cin.ignore() without any arguments will only clear 1 character from the input buffer which may not be what you had envisioned.