I am using Dev C++ and I get linker errors for playgame, loadgame and playmultiplayer, I am copying the code from a tutors hand out, I have checked and triple checked and I have copied it correctly. Thank you in advance for any help.
#include <iostream>
usingnamespace std;
void playgame();
void loadgame();
void playmultiplayer();
int main()
{
int input;
cout << "1. Play game\n";
cout << "2. Load game\n";
cout << "3. Play multiplayer\n";
cout << "4. Exit\n";
cout << "Selection: ";
cin >> input;
switch ( input ) {
case 1: // Note the colon, not a semicolon
playgame();
break;
case 2: // Note the colon, not a semicolon
loadgame();
break;
case 3: // Note the colon, not a semicolon
playmultiplayer();
break;
case 4: // note the colon, not a semicolon
cout << "Thank you for playing!\n";
break;
default: "Error, bad input, quitting\n";
break;
}
cin.get();
return 0;
}
In the code that you show, you do declare on line 5 that there is a function with name "playgame". Without that declaration the compiler could not compile the function "main", specifically the line 21. Good so far.
The linker on the other hand has to hook up the compiled implementation of the "playgame" so that the binary can actually execute the function when the main function calls it. The error is thus probably that the linker cannot find from any of the object files or libraries implementation for the void playgame().
You need to have a
1 2 3 4
void playgame()
{
// something
}
It does not need to be in the same source file as main, but it has to be compiled and included for linking.