Why cant i compile?

closed account (2A7X92yv)
This is my header

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef PARTY_H
#define PARTY_H

struct Party
{
	char *	pName;
	int		Size;
	char	Plane;
};

#endif

#ifndef PLANE_H
#define PLANE_H

struct Plane
{
	Party *	Who;
	int		NumSeats;
	int		HowManyOccupied;
	int		HowManyParties;
};

#endif

int ReadInt ();
char * ReadString();
void FitOntoPlane (Plane & PlaneChecked, Plane & Lounge, Party CurrentParty);
void FlyAlfa (Plane & PlaneChecked, Plane & Lounge, char WhichPlane);
void FlyBravo (Plane & PlaneChecked, Plane & Lounge, char WhichPlane);

Thts my Main.. THE ERROR I GET IS

1>Main.obj : error LNK2019: unresolved external symbol "int __cdecl ReadInt(void)" (?ReadInt@@YAHXZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "char * __cdecl ReadString(void)" (?ReadString@@YAPADXZ) referenced in function _main
#include <iostream>

using namespace std;

#include "Headers.h"

void main ()
{
	Plane	Alfa;
	Plane	Bravo;
	Plane	Lounge;
	Party	NewArrival;		// this contains the info about the next party to arrive
	char *	pPlaneName;
	bool	Shutdown = false;
	bool	RightCommand = false;

	do
	{
		cout << "Please enter a command: ";
		pPlaneName = ReadString();

		if (_strcmpi (pPlaneName, "ALFA") == 0)
		{
			cout << "Number of seats on ALFA: ";
			Alfa.NumSeats = ReadInt ();
			Alfa.HowManyOccupied = 0;
			Alfa.HowManyParties = 0;
			Alfa.Who = new Party [Alfa.NumSeats];
		}

		else if (_strcmpi (pPlaneName, "BRAVO") == 0)
		{
			cout << "Number of seats on BRAVO: ";
			Bravo.NumSeats = ReadInt ();
			Bravo.HowManyOccupied = 0;
			Bravo.HowManyParties = 0;
			Bravo.Who = new Party [Bravo.NumSeats];
		}

		else if (_strcmpi (pPlaneName, "LOUNGE") == 0)
		{
			cout << "Number of seats in the LOUNGE: ";
			Lounge.NumSeats = ReadInt ();
			Lounge.HowManyOccupied = 0;
			Lounge.HowManyParties = 0;
			Lounge.Who = new Party [Lounge.NumSeats];
		}

		else if (_strcmpi (pPlaneName, "ARRIVE") == 0)
		{
			do
			{
				cout << "Which plane: ";
				pPlaneName = ReadString ();
				if (_strcmpi (pPlaneName, "ALFA") == 0)
				{
					NewArrival.Plane = 'A';
					RightCommand = true;
				}
				else if (_strcmpi (pPlaneName, "BRAVO") == 0)
				{
					NewArrival.Plane = 'B';
					RightCommand = true;
				}
				else
				{
					cout << "Bad Command" << endl;
					cout << endl;
				}
			}while (!RightCommand);
			RightCommand = false;

			cout << "Name of party: ";
			NewArrival.pName = ReadString ();
			cout << "Number in party: ";
			NewArrival.Size = ReadInt ();

			if (NewArrival.Plane == 'A')
				FitOntoPlane (Alfa, Lounge, NewArrival);
			else if (NewArrival.Plane == 'B')
				FitOntoPlane (Bravo, Lounge, NewArrival);

			if (Alfa.HowManyOccupied == Alfa.NumSeats)
				FlyAlfa (Alfa, Lounge, 'A');
			else if (Bravo.HowManyOccupied == Bravo.NumSeats)
				FlyBravo (Bravo, Lounge, 'B');
		}

		else if (_strcmpi (pPlaneName, "FLY") == 0)
		{
			do
				{
				cout << "Which plane: ";
				pPlaneName = ReadString();
				if (_strcmpi (pPlaneName, "ALFA") == 0)
				{
					FlyAlfa (Alfa, Lounge, 'A');
					RightCommand = true;
				}
				else if (_strcmpi (pPlaneName, "BRAVO") == 0)
				{
					FlyBravo (Bravo, Lounge, 'B');
					RightCommand = true;
				}
				else
				{
					cout << "Bad Command" << endl;
					cout << endl;
				}
			} while (!RightCommand);
			RightCommand = false;
		}

		else if (_strcmpi (pPlaneName, "SHUTDOWN") == 0)
		{
			do
			{
				FlyAlfa (Alfa, Lounge, 'A');
			} while (Alfa.HowManyOccupied != 0);
			do
			{
				FlyBravo (Bravo, Lounge, 'B');
			} while (Bravo.HowManyOccupied !=0);
			Shutdown = true;
		}

		else
			cout << "Bad Command" << endl;
		
		cout << endl;
		delete [] pPlaneName;
	} while (!Shutdown);
}
"Unresolved external symbol" usually means you are calling a function that has no body.

In this case, you are calling "ReadInt" and "ReadString", but you never gave those functions a body.


EDIT: also, you really should consider using string instead of char*. You'll save yourself tons of headaches.
Last edited on
closed account (2A7X92yv)
Can u please tell me where to change. And wht to change. Pls help
I already did. =P

You need to add bodies for ReadInt and ReadString. IE: write the actual code for them:

1
2
3
4
5
6
7
8
9
10
int ReadInt ()
{
  // put your code here
}


char * ReadString()
{
  // put your code here
}
Last edited on
closed account (2A7X92yv)
so ur saying.. i shuld add this in the MAIN.CPP... where it says char* ReadString()? Sorry i am newbie.. .. i am really sorry to disturb u again and again
closed account (2A7X92yv)
ok so i got it... Now.. it says [Linker error] undefined reference to `ReadString()'

why??
Topic archived. No new replies allowed.