2 Replies - 1228 Views - Last Post: 07 February 2009 - 07:41 AM Rate Topic: -----

#1 sdo  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 59
  • Joined: 06-February 09

error LNK2019: unresolved external symbol

Posted 07 February 2009 - 07:26 AM

Hey All,

The compiler seems to have a linking issue with one of my own functions.. Simple project with only 1 .cpp and 1 .h file, see both below.

RandomMaze.cpp

#include "RandomMaze.h"
#include <iostream> 
#include <ctime> 
#include <cstdlib>
#include <climits>
#include <cmath>

using namespace std;

RandomMaze::RandomMaze(void){

}

RandomMaze::~RandomMaze(void){

}

RandomMaze::RandomMaze(char* in){
	generateMaze(in);
}

void RandomMaze::generateMaze(char* in){
	int n,rand;
	//char *maze = NULL;

	//int** maze; 


	if (strlen(in) < 15){
		n = atoi(in);
		maze = new int*[n];
		//maze = new char[n][n];

	for (int k=0; k < n; k++){
		maze[k] = new int[n];
		cout << maze[k];
	}

		for (int i = 0; i < n; i++) {
			for (int k = 0; k < n; k++) {
				rand = randInt(0,n);
				maze[i][k] = rand;
			}
		}
	}else {
		cout << "ERROR: PARAMETER TOO LARGE, MAZE REVERTED TO RANDOM GENERATION" << endl;
		// random generation here
	}
	

}



int randInt(int lowest, int highest) {
	srand((unsigned)time(0)); 
	int random_integer; 
	int range=(highest-lowest)+1; 
		random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));

		return random_integer;
}

void RandomMaze::printMaze(void){

}

int main(){

cout << "ANYTHING";

	//generateMaze(4);

}


RandomMaze.h

#pragma once

class RandomMaze {

public:

	RandomMaze(void);
	~RandomMaze(void);
	RandomMaze(char*);
	
	void generateMaze(char*);
	void printMaze(void);
	

private:

	int** maze; 

	int randInt(int,int);
	
};


When I try to build this I get:

1>RandomMaze.obj : error LNK2019: unresolved external symbol "private: int __thiscall RandomMaze::randInt(int,int)" (?randInt@RandomMaze@@AAEHHH@Z) referenced in function "public: void __thiscall RandomMaze::generateMaze(char *)" (?generateMaze@RandomMaze@@QAEXPAD@Z)
1>C:\Documents and Settings\User 1\My Documents\Visual Studio 2008\Projects\Project1\Debug\Project1.exe : fatal error LNK1120: 1 unresolved externals


Any ideas?

SDO


Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2019: unresolved external symbol

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6111
  • View blog
  • Posts: 23,672
  • Joined: 23-August 08

Re: error LNK2019: unresolved external symbol

Posted 07 February 2009 - 07:40 AM

Change this:
int randInt(int lowest, int highest) {

to
int RandomMaze::randInt(int lowest, int highest) {

Was This Post Helpful? 1
  • +
  • -

#3 sdo  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 59
  • Joined: 06-February 09

Re: error LNK2019: unresolved external symbol

Posted 07 February 2009 - 07:41 AM

View PostJackOfAllTrades, on 7 Feb, 2009 - 06:40 AM, said:

Change this:
int randInt(int lowest, int highest) {

to
int RandomMaze::randInt(int lowest, int highest) {


*FacePalm*

Thanks Jack.

SDO
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1