Unresolved externals, code doesn't look like anything is wrong yet won't debug

I have been staring at this for one hour and do not understand what I'm doing wrong. Debugger is saying I have unresolved externals yet everything looks perfect to me, but of course the computer is never wrong so I must be doing something wrong. The '->setNext', and 'setItem' functions are defined in a 'Node.h' header file provided from my class.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include "Node.h"
using namespace std;

void createMap();

struct city{
	char city_name;
	bool visited;
	Node<char> *adjacent_city;
};

int const MAX=9; //currently the company serves 9 cities
city flightMap[MAX]; // declare a global array for flight map;

int main() {
	createMap();
	return 0;
}

void createMap() {
	Node<char> *D_ptr;
	Node<char> *E_ptr;
	Node<char> *H_ptr;

	flightMap[0].city_name='A';
	flightMap[0].visited=false;
	flightMap[0].adjacent_city=new Node<char>;
	flightMap[0].adjacent_city->setItem('B');
	flightMap[0].adjacent_city->setNext(NULL);

	flightMap[1].city_name='B';
	flightMap[1].visited=false;
	flightMap[1].adjacent_city=NULL;

	flightMap[2].city_name='C';
	flightMap[2].visited=false;
	flightMap[2].adjacent_city=new Node<char>;
	flightMap[2].adjacent_city->setItem('B');
	flightMap[2].adjacent_city->setNext(NULL);
	
	flightMap[3].city_name='D';
	flightMap[3].visited=false;
	flightMap[3].adjacent_city=new Node<char>;
	flightMap[3].adjacent_city->setItem('C');
	D_ptr=new Node<char>;
	D_ptr->setItem('E');
	D_ptr->setNext(NULL);
	flightMap[3].adjacent_city->setNext(D_ptr);
				
	
	flightMap[4].city_name='E';
	flightMap[4].visited=false;
	flightMap[4].adjacent_city=new Node<char>;
	flightMap[4].adjacent_city->setItem('F');
	E_ptr=new Node<char>;
	E_ptr->setItem('H');
	E_ptr->setNext(NULL);
	flightMap[4].adjacent_city->setNext(E_ptr);
				
	flightMap[5].city_name='F';
	flightMap[5].visited=false;
	flightMap[5].adjacent_city=new Node<char>;
	flightMap[5].adjacent_city->setItem('G');
	flightMap[5].adjacent_city->setNext(NULL);

	flightMap[6].city_name='G';
	flightMap[6].adjacent_city=new Node<char>;
	flightMap[6].adjacent_city->setItem('F');
	flightMap[6].adjacent_city->setNext(NULL);

	flightMap[7].city_name='H';
	flightMap[7].visited=false;
	flightMap[7].adjacent_city=new Node<char>;
	flightMap[7].adjacent_city->setItem('E');
	H_ptr=new Node<char>;
	H_ptr->setItem('C');
	H_ptr->setNext(NULL);
	flightMap[7].adjacent_city->setNext(H_ptr);
			
	flightMap[8].city_name='I';
	flightMap[8].visited=false;
	flightMap[8].adjacent_city=NULL;
				
	}


here is the header file, I figured this part is correct since it is a template for the class.
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _NODE
#define _NODE

template<class ItemType>
class Node
{
private:
	ItemType       item;
	Node<ItemType> *next;
public:
	Node();  //default constructor
	Node(const ItemType &anItem); //none default constructor #1
	Node(const ItemType &anItem, Node<ItemType> *nextPtr); //none default constructor #2
	void setItem(const ItemType &anItem);
	void setNext(Node<ItemType> *nextPtr);
	ItemType getItem() const;
	Node<ItemType> *getNext() const;
};
template<class ItemType>
Node<ItemType>::Node() {
	next=NULL;
}

template<class ItemType>
Node<ItemType>::Node(const ItemType &anItem) {
	item=anItem;
}

template<class ItemType>
Node<ItemType>::Node(const ItemType &anItem,Node<ItemType> *nextPtr) {
	item=anItem;
	next=nextPtr;
}

template<class ItemType>
void Node<ItemType>::setItem(const ItemType &anItem) {
	item=anItem;
}

template<class ItemType>
void Node<ItemType>::setNext(Node<ItemType> *nextPtr) {
	next=nextPtr;
}

template<class ItemType>
ItemType Node<ItemType>::getItem() const {
	return item;
}

template<class ItemType>
Node<ItemType>* Node<ItemType>::getNext() const {
	return next;
}
#endif 


the actual unresolved external errors
1
2
3
#1 - error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup	

#2 - Error	2	error LNK1120: 1 unresolved externals	 

Last edited on
Usually, unresolved externals are when your function parameters/arguments are missing somewhere.
What is the code in file "Node.h" ?
unresolved externals are when your function parameters/arguments are missing somewhere

That's not correct. The compiler will flag will parameters/arguments that are missing.

Unresolved externals occur when you declare functions but do not implement them.

@OP - You haven't show us the declarations and implementation for your node class.
It would also be helpful if you posted the exact error message you're getting from the linker.
Last edited on
Thank you all for the comments so far. I've updated the OP with more information so I'd appreciate any help on this. Thanks!
_WinMain@16 referenced in function ___tmainCRTStartup


I have a vague idea that, this is do with your project being configured as Windows GUI project as opposed to a console app.

I don't use windows, so I could be completely wrong - it is just I remember this sort of problem being mentioned in the past.

EDIT: Also realise the difference between compiler / linker errors and using a debugger program. At the moment you have linker errors. Debugging allows one to step through a program (which must compiled into an executable first) line by line and watch the values of variables (amongst other things), then deduce where it all went wrong.
Last edited on

I have a vague idea that, this is do with your project being configured as Windows GUI project as opposed to a console app.

I don't use windows, so I could be completely wrong - it is just I remember this sort of problem being mentioned in the past.

! holy cow this was the problem, I created the project as a windows application vs. console...thanks that definitely solved my problem!!!!
Topic archived. No new replies allowed.