On previous lecture we learnt, that the & can be used to force the system to pass on values from the same named variable (argument) to the function’s variable (parameters). void greet(string& names);
That does not seem to work if we put the definition on the greet.cpp file nor if put on the header file. Does this mean it cannot be used in linked files at all? And does this now cause three names to be existing at the same time thus tripling the amount of data stored on name(s)?
Could you be more specific about what did not work? Writing exact contents of the involved files and any errors you are getting for any command you run is helpful.
I get the errors LNK1120 and LNK2019. Without the & no errors and it compiles fine. I am on Visual Studio 2022 Common
If I put the & on both, I get an error “C2644, void greet(std::string &) cannot convert argument 1 from const char to std::string &”
I do not have char type anywhere… but I think it is thinking & is the char in question, it does not say the entire argument: (std::string& name) it just says sdt::string &, which resulted me thinking & is incompatible with the separate files.
Sorry for replying to an old question.
But can you show us (me) your approach
?
I have also received those linking errors but in different contexts.
Yeah I had a bad version of Visual Studio. Reinstallation fixed this.
Kindly answer those questions:
- Which version was your previous version?
- Which version is your current version?
- Do you use MinGW compiler or VC++ library?
My currently open topic may be related to it.
Thank you.
The previous version was 4 something, I now have the 6. I also switched computers, so idk if having better machine had anything to do with it.
Well. I will try recreating the question in consideration.