I am getting these errors when trying to compile my prodject, I do not think there is anything wrong with my code. Please help
Error 1 error LNK2005: "void __cdecl welcome(void)" (?welcome@@YAXXZ) already defined in functions.obj c:\Users\Dylan\documents\visual studio 2013\Projects\Robot Masters - Text Based\main.obj Robot Masters - Text Based
Error 2 error LNK1169: one or more multiply defined symbols found c:\users\dylan\documents\visual studio 2013\Projects\Robot Masters - Text Based\Debug\Robot Masters - Text Based.exe Robot Masters - Text Based
main.cpp should include functions.h -- not functions.cpp.
As you've included the definition (implementation) of welcome in main.cpp the function will be compiled into both main.obj and functions.obj (hence the linker warning about multiply defined symbols.)
Edit: And as shadowmouse has mentioned (below) the signature of the declaration of welcome() in your header should match that of the implementation in functions.cpp
If you don't fix this you'll get a different linker warning - about an unresolved external - as the linker needs void welcome(); (the function you're using in main) whereas you've implemented void welcom(int number); (a different overload of the function.)
The signatures of your functions welcome() are different, they should be the same. You have welcome(int number) and welcome(void). As you're calling welcome() in main.cpp without an input, I presume the one in functions.cpp is correct and you should remove the int number from functions.h. I do question the premise of the function though, you're creating an integer without initialising it to a value and then printing it in a function called welcome, this will probably just come up with a random number, is that what you're trying to do?
First of all, you need to change your welcome function's prototype in you functions.h (because it doesn't match with what you have in your functions.cpp
so in you functions.h file, replace your line 3 with this:
1 2 3
void welcome(); // you will be asking the user to input the number
// you are already declaring int number in your function's body
// and so there's no need to pass the number as a parameter
Then,
In you main.cpp,
instead of including functions.cpp, include the functions.h.
So replace line 1 with this: #include "functions.h"
Then,
to call the welcome function, you need to create a class object.
So replace line 5 with this: