fatal error LNK1120: 1 unresolved externals

im guessing this is a linking error but i do not know how to fix it

Page 1 of 1

3 Replies - 2917 Views - Last Post: 25 October 2010 - 04:42 PM Rate Topic: -----

#1 TheGlyde  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-October 10

fatal error LNK1120: 1 unresolved externals

Posted 25 October 2010 - 02:38 PM

#ifndef LexA_H
#define LexA_H
#include <iostream>
using namespace std;

class LexA
{
public:
	int charClass, lexLen,
		token, nextToken;
	char lexeme[100], nextChar;

private:
	char character;

public:
	LexA();
	LexA(char);
	void addChar();
	void getChar();
	void getNonBlank();
	int lex();
	int lookup(char);

};
#endif

#include <iostream>
#include "LexA.h"
using namespace std;

LexA::LexA(char dummy)
{
	character = dummy;

}

int LexA::lookup(char ch)
{
	int assign_op = 20, add_op = 21,
		sub_op = 22, mult_op = 23, div_op = 24, left_paren = 25,
		right_paren = 26;

	switch(ch)
	{
	case '(':
		addChar();
		nextToken = left_paren;
		break;

	case ')':
		addChar();
		nextToken = right_paren;
		break;

	case '+':
		addChar();
		nextToken = add_op;
		break;

	case '-':
		addChar();
		nextToken = sub_op;
		break;

	case '*':
		addChar();
		nextToken = mult_op;
		break;

	case '/':
		addChar();
		nextToken = right_paren;
		break;
		
	default:
		addChar();
		nextToken = EOF;
		break;
	}

	return nextToken;
}

void LexA::addChar()
{
	if(lexLen <= 98)
	{
		lexeme[lexLen++] = nextChar;
		lexeme[lexLen] = 0;
	}
	else
		cout <<" Error - Lexeme too long!!!" <<endl;
}

void LexA::getChar()
{
	int letter = 0, digit = 1, unknown = 99;

	if ((nextChar = character) != EOF)
	{
		if(isalpha(nextChar))
			charClass = letter;
		else if(isdigit(nextChar))
			charClass = digit;
		else charClass = unknown;
	}
	else
		charClass = EOF;
}

void LexA::getNonBlank()
{
	while (isspace(nextChar))
		getChar();
}

int LexA::lex()
{
	const int letter = 0, digit = 1, unknown = 99, int_lit = 10, ident = 11;

	lexLen = 0;
	getNonBlank();
	
	switch (charClass)
	{
	case letter:
		addChar();
		getChar();

		while (charClass == letter || charClass == digit)
		{
			addChar();
			getChar();
		}
		nextToken = ident;
		break;

	case digit:
		addChar();
		getChar();

		while (charClass == digit)
		{
			addChar();
			getChar();
		}
		nextToken = int_lit;
		break;

	case unknown:
		lookup(nextChar);
		getChar();
		break;

	case EOF:
		nextToken = EOF;
		lexeme[0] = 'E';
		lexeme[1] = 'O';
		lexeme[2] = 'F';
		lexeme[3] = 0;
		break;
	}

	cout <<"Next token is: " << nextToken << " Next lexeme is " << lexeme <<endl;

	return nextToken;
}

#include <iostream>
#include <fstream>
#include "LexAImp.cpp"
#include "LexA.h"
using namespace std;

int main()
{
	LexA lexical;
	ifstream inFile;
	char letter;

	inFile.open("source.txt", ios::in);
	letter = inFile.get();


	while (letter != EOF)
	{
		cout << letter <<endl;
		letter = inFile.get();
		
		lexical.lex();
	}
	

	inFile.close();

	return 0;
}



that is my code.... and this is the error i am getting... does anyone know how to fix this problem so i can move on with my project

--------------------Configuration: LexADriver - Win32 Debug--------------------
Linking...
LexADriver.obj : error LNK2001: unresolved external symbol "public: __thiscall LexA::LexA(void)" (??0LexA@@QAE@XZ)
Debug/LexADriver.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

LexADriver.exe - 2 error(s), 0 warning(s)

Is This A Good Question/Topic? 0
  • +

Replies To: fatal error LNK1120: 1 unresolved externals

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: fatal error LNK1120: 1 unresolved externals

Posted 25 October 2010 - 02:44 PM

LexA lexical;



Your class declares but does not define a constructor that takes no arguments. Add

LexA::LexA() {};


Was This Post Helpful? 0
  • +
  • -

#3 TheGlyde  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-October 10

Re: fatal error LNK1120: 1 unresolved externals

Posted 25 October 2010 - 04:27 PM

what do i need to do to fix this problem
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6037
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: fatal error LNK1120: 1 unresolved externals

Posted 25 October 2010 - 04:42 PM

I do believe it's right there in n8wxs's post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1