error LNK2019

I am recieving an link error message when I try to run my code.

Page 1 of 1

6 Replies - 937 Views - Last Post: 02 November 2008 - 04:43 PM Rate Topic: -----

#1 Winterhawk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-July 08

error LNK2019

Post icon  Posted 31 October 2008 - 07:02 PM

Once I try to run my code I am getting four errors. The errors that I am recieving is
1>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Menu::displayChoice(void)" (?displayChoice@Menu@@QAEXXZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Menu::displayMenu(void)" (?displayMenu@Menu@@QAEXXZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Menu::displayTitle(void)" (?displayTitle@Menu@@QAEXXZ) referenced in function _main
fatal error LNK1120: 3 unresolved externals


Here is my code as of now:

Menu.cpp
#include <iostream>
#include "Menu.h"


 
using namespace std;
 
void displayTitle()
{
	 cout << "Welcome to hangman!"<<endl;
}
void displayHeader()
{
	cout <<"Information contained in Menu.h"<<endl;// Display header
}
void displayMenu () // Display menu
{
	cout << "*****************************************************************" << endl;
	cout << "*	   M E N U	   *" << endl;
	cout << "*	   Type 'q' to Quit *" << endl;
	cout << "*****************************************************************" << endl;
	cout << "	(a)dd a word" << endl;
	cout << "	(d)elete a word" << endl;
	cout << "	(l)ist all word" << endl;
	cout << "	(s)earch for a word" << endl;
	cout << "	(p)lay game" << endl;
	cout << "*****************************************************************" << endl;
}
void displayChoice () // Ask for a choice from the menu
{
	cout << "Please enter your choice: " <<endl;
}
 



Menu.h
#ifndef MENU_H
#define MENU_H

#include <iostream>

using namespace std;

class Menu
{

public:
	void displayTitle();
	// Function to output the name of the game
	// Postcondition: Outputs
	//				  Welcome to Hangman!
	void displayHeader();
	// Function to output the header of the game
	// Postcondition: Outputs
	//				  Please follow the instructions...
	void displayMenu();
	// Function to output the menu of the game
	// Postcondition: Outputs
	//*****************************************************************
	//*	   M E N U	   *
	//*	   Type 'q' to Quit *
	//*****************************************************************
	//	(a)dd a word
	//	(d)elete a word
	//	(l)ist all word
	//	(s)earch for a word
	//	(p)lay game
	//*****************************************************************
	void displayChoice();
	// Function to output a message to the user asking for a choice.
	// Postcondition: Outputs
	//				  Please enter your choice:
	char getChoice();
	// Accessor method (or getter)
	void setChoice(char sel);
	// Mutator method (or setter)
	

};

#endif 



Hangmanmenu.h
#ifndef HANGMANMENU_H
#define HANGMANMENU_H

#include <iostream>
#include "Menu.h"

using namespace std;
 
class Hangmanmenu : public Menu
{
public:
	void displayMenu();
	
};
#endif 

 


Hangmanmenu.cpp
#include <iostream>
#include "Hangmanmenu.h"
 
using namespace std;
 
void displayMenu (); 

void displayChoice (); // Ask for a choice from the menu




Main.cpp
#include <iostream>
#include <iomanip>
#include <string>
#include "Menu.h"
#include "Hangmanmenu.h"
 
using namespace std;
 
int main ()
{
	string word;
	char choice;

	 Hangmanmenu hman = Hangmanmenu();
	 Menu hmenu = Menu();

	 hmenu.displayTitle(); // Call to display title
	 hmenu.displayMenu(); // Call to display menu
	 hmenu.displayChoice(); //Call to ask user for a choice
	 

	 
	 return 0;
}



Can someone please help me out? Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2019

#2 DoubleFission  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 223
  • Joined: 20-September 08

Re: error LNK2019

Posted 31 October 2008 - 07:24 PM

#include <iostream>
#include "Menu.h"

using namespace std;

void Menu::displayTitle()
{
	 cout << "Welcome to hangman!"<<endl;
}
void Menu::displayHeader()
{
	cout <<"Information contained in Menu.h"<<endl;// Display header
}
void displayMenu () // Display menu
{
	cout << "*****************************************************************" << endl;
	cout << "*	   M E N U	   *" << endl;
	cout << "*	   Type 'q' to Quit *" << endl;
	cout << "*****************************************************************" << endl;
	cout << "	(a)dd a word" << endl;
	cout << "	(d)elete a word" << endl;
	cout << "	(l)ist all word" << endl;
	cout << "	(s)earch for a word" << endl;
	cout << "	(p)lay game" << endl;
	cout << "*****************************************************************" << endl;
}
void Menu::displayChoice () // Ask for a choice from the menu
{
	cout << "Please enter your choice: " <<endl;
}


You left out the 'Menu::' before the functions in menu.h

The Menu:: indicates that the function belongs to that class.
Was This Post Helpful? 0
  • +
  • -

#3 Winterhawk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-July 08

Re: error LNK2019

Posted 31 October 2008 - 08:28 PM

View PostDoubleFission, on 31 Oct, 2008 - 07:24 PM, said:

#include <iostream>
#include "Menu.h"

using namespace std;

void Menu::displayTitle()
{
	 cout << "Welcome to hangman!"<<endl;
}
void Menu::displayHeader()
{
	cout <<"Information contained in Menu.h"<<endl;// Display header
}
void displayMenu () // Display menu
{
	cout << "*****************************************************************" << endl;
	cout << "*	   M E N U	   *" << endl;
	cout << "*	   Type 'q' to Quit *" << endl;
	cout << "*****************************************************************" << endl;
	cout << "	(a)dd a word" << endl;
	cout << "	(d)elete a word" << endl;
	cout << "	(l)ist all word" << endl;
	cout << "	(s)earch for a word" << endl;
	cout << "	(p)lay game" << endl;
	cout << "*****************************************************************" << endl;
}
void Menu::displayChoice () // Ask for a choice from the menu
{
	cout << "Please enter your choice: " <<endl;
}


You left out the 'Menu::' before the functions in menu.h

The Menu:: indicates that the function belongs to that class.



Thanks for the help but, I am still getting the same errors as before. Any more suggestion or tips will help.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: error LNK2019

Posted 31 October 2008 - 09:00 PM

As DoubleFission stated, any member functions you are implementing in your cpp files need to be prefaced with the name of the class to which they belong, so that the linker can link the defined function with its declaration.
Was This Post Helpful? 0
  • +
  • -

#5 Winterhawk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-July 08

Re: error LNK2019

Posted 01 November 2008 - 08:59 PM

View PostJackOfAllTrades, on 31 Oct, 2008 - 09:00 PM, said:

As DoubleFission stated, any member functions you are implementing in your cpp files need to be prefaced with the name of the class to which they belong, so that the linker can link the defined function with its declaration.

I am a little lost I did what was suggested. Why I am still getting the same error messages. Please help me understand.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: error LNK2019

Posted 02 November 2008 - 05:57 AM

You're going to have to post all your code again, so we can see where things stand at this point.
Was This Post Helpful? 0
  • +
  • -

#7 Winterhawk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-July 08

Re: error LNK2019

Posted 02 November 2008 - 04:43 PM

View PostJackOfAllTrades, on 2 Nov, 2008 - 05:57 AM, said:

You're going to have to post all your code again, so we can see where things stand at this point.


Quote

Thanks for the help and suggestions but, figured it out I had my Menu:: in the wrong file. Menu:: was suppose to be in the .cpp file not the .h file.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1