Unresolved token and external symbol with ctor and dtor

I've been trying to get rid of these linking errors for a few days now and the only thing that does it is commenting out the constructors and destructors for my two classes..

Here are the errors:

1>Project.obj : error LNK2028: unresolved token (0A00000C) "public: __thiscall Room::~Room(void)" (??1Room@@$$FQAE@XZ) referenced in function "int __cdecl build2Rooms(void)" (?build2Rooms@@$$FYAHXZ)
1>Project.obj : error LNK2028: unresolved token (0A00000D) "public: __thiscall Room::Room(void)" (??0Room@@$$FQAE@XZ) referenced in function "int __cdecl build2Rooms(void)" (?build2Rooms@@$$FYAHXZ)
1>Project.obj : error LNK2019: unresolved external symbol "public: __thiscall Room::~Room(void)" (??1Room@@$$FQAE@XZ) referenced in function "int __cdecl build2Rooms(void)" (?build2Rooms@@$$FYAHXZ)
1>Project.obj : error LNK2019: unresolved external symbol "public: __thiscall Room::Room(void)" (??0Room@@$$FQAE@XZ) referenced in function "int __cdecl build2Rooms(void)" (?build2Rooms@@$$FYAHXZ)
1>Y:\Project\Debug\Project.exe: fatal error LNK1120: 4 unresolved externals


And here is my code..

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
// Project.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include "conio.h"
//#include <string>
#include "Room.h"
#include "Paths.h"


int build2Rooms()
{
	//Room hereIsRoom1 = Room();
	//hereIsRoom1.getShortDescription();
	Room hereIsRoom2 = Room();

	return 0;
}

using namespace std;

int main()
{

	build2Rooms();
	

	_getch();
    return 0;
}



1
2
3
4
5
6
7
8
9
10
11
12
	Path::Path()
	{
	//string pathID;
	// Default constructor, sets values to null
	pathID = "NULL";
	}

	
	Path::~Path()
	{
	// Default destructor
	}


1
2
3
4
5
6
7
8
9
10
11
12
	Room::Room()
	{
		//Default Constructor
		shortDescription = "NULL";
		longDescription = "NULL";
	}


	Room::~Room()
	{
		//Default destructor
	}


I've read about adjusting linkers, etc.. etc.. which is honestly beyond me at this point.. if someone can point me in the right direction to learn about adjusting those settings that would be great..

but if I comment out the constructor and destructor, I receive no linking errors and everything compiles fine (when the compiler generates the constructors and destructors..)

I also read that VC++ 2010, which I am using, requires you to define functions with no argument list as sampleFunction(void) instead of sampleFunction() . This did not solve the problem so I removed the excess from my code.

I am new, and if you only gave me a list of articles to read to find the answer I would be happy, but I have searched for days now and found no solution.

Thanks ahead of time.
Could you post the class declarations?

SgtPooki wrote:
I also read that VC++ 2010, which I am using, requires you to define functions with no argument list as sampleFunction(void) instead of sampleFunction() .

This is not true. They mean the same thing as far as the C++ standard is concerned. I use VC++ Express 2010 and I never ever use the C style empty argument list. Note that in C those two expression have different meanings.
Try changing: Room hereIsRoom2 = Room(); to Room hereIsRoom2;
Maybe you forgot to add to your project the cpp file with the definitions for the functions of your classes.
Last edited on
I can post the class declarations.. you want the implementation file, the interface file, or both?

The class declarations are about 100 lines each, with Room.cpp being 165 (not all of the functions do much.. but they are all declared properly.


Also, I've tried Room hereIsRoom2; and it generates the same errors.

I can take a look if you post all of it.
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
Interface file Paths.h, describes the class that is to be held in an array of the room class to determine which exits are available.

Description: A Room is a place in the virtual world where NPCs, creatures, players, items, stores/shops, 
weather, and many other things can exist. The room must be able to move an item to and from itself, 
collect garbage if items have been laying around too long, etc..


*/

#include "stdafx.h"

//#include "Paths.h"

class Path;

class Room
{
//*	
private:
	
	Path *_thisPath;

	std::string name;
	// The name of the room

	int locationX;
	// Holds the location of the x coordinate of the room

	int locationY;
	// Holds the location of the y coordinate of the room

	int locationZ;
	// Holds the location of the z coordinate of the room

	//Entity entityList[];
	// Array of objects holds a list of objects located in this object

	Path * pathsList[15];
	// Array of objects that holds the paths available for this room; the links to other rooms.

	std::string longDescription;
	// The rooms description, its visual appearance in words, stored in a string.
	
	std::string shortDescription;
	// The rooms description, its visual appearance in words, stored in a string.

//*/
public:

///*

	//***** Methods *****


	int getXLocation();
	// Returns the X location

	int getYLocation();
	// Returns the Y location

	int getZLocation();
	// Returns the Z location

	void setXLocation(int newXvalue);
	// sets the X location

	void setYLocation(int newYvalue);
	// sets the Y location

	void setZLocation(int newZvalue);
	// sets the Z location

//	void addEntity(Entity entityToAdd);
	// Adds the entity to the Rooms’s entityList[] array.

//	void removeEntity(Entity entityToRemove);
	// Removes an entity from the Room’s entityList[] array

	void addPath(Path * pathToAdd);
	// Check the database, or the map table, whatever, for the paths, and assign the paths to this room
	// adds the path to the pathList[] array

	void removePath(Path * pathToRemove);
	// Removes a path from the pathList[] array

	void setLocations();  //********     MAY NOT NEED       *******
	//  Check the database, or the map table, whatever, for the locations of rooms, and assign the x y z values

	void checkPath();
	// Call when a user is trying to move, or object is trying to be thrown (cool idea) in a certain direction:
	// check if there is a path in this direction and if it is navigable

	void setName(std::string);
	// sets this room's name

	std::string getName();
	// returns this room's name
	
	void setDescription(std::string longDescriptionToSet, std::string shortDescriptionToSet);
	// Set description of the long and short descriptions
	
	void setLongDescription(std::string longDescriptionToSet);
	// Set description of the long and short descriptions
	
	void setShortDescription(std::string shortDescriptionToSet);
	// Set description of the long and short descriptions

	std::string getLongDescription();
	// Set description of the long and short descriptions
	
	std::string getShortDescription();
	// Set description of the long and short descriptions
///*
	Room::Room();
		//Default Constructor
	
	Room::~Room();
		//Default destructor
//*/

};

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
Implementation file Paths.cpp, defines the class that is to be held in an array of the room class to determine which exits are available.



*/

#include "stdafx.h"
#include "Room.h"
//#include <string>



class Path
{

private:
	
	Room *_thisRoom;

	//***** Variables / Properties *****//
	
	std::string name;
	// Variable holds the name of the object, which may also be stored in a list to be searched for

	std::string pathID;
	// Variable holds the unique ID of this path. Should be 5 characters long

	bool visible;
	// Variable determines whether this object can be seen by the user or not

	bool canUse;
	// Variable determines whether this object can be used by the user or not (hidden exit you can fall through, or search for)

	Room * roomOwner;
	// Variable stores the address of the room object that owns this path.

	Room * destinationRoom;
	// Variable holds the memory address of the room that the path leads to



public:



	//***** Methods *****//
	Room * getRoomOwner()
	{
	// Returns the room that contains this path object in its ExitsAvailable[] array, &roomOwner
	return roomOwner;
	}
	
	void setRoomOwner(Room * roomAddress)
	{
	// Sets the room owner that contains this path object in its ExitsAvailable[] array
    roomOwner = roomAddress;
	}


	Room * getDestinationRoom()
	{
	// Returns a pointer to the room object that this path leads to, &destinationRoom
		return destinationRoom;
	}

	void setDestinationRoom(Room * roomAddress)
	{
	// Sets the room object that this path leads to
	}
	
	std::string getPathID()
	{
	// Returns the unique identifier for this path, PathID
		return pathID;
	}

	void setPathID()
	{
	// Sets the unique identifier for this path, PathID
	}

	bool canNavigate()
	{
	// Returns true if the character or NPC has the proper skills, or is of the proper size to navigate the specified path.
	// (small enough for a hole, nimble enough for a cliff, fit enough to swim a river..) and also if the exit has canUse set to true
		return false;
	}

	template <class object>
	void Travel(object moveThisObject)
	{
	// Moves an object from from the roomOwner to the destinationRoom
	}
	
	void Hide(bool)
	{
	// true : Hides the path but can be searched for and found.
	// false : Hides the path and it cannot be searched for or found at all.
	}

	void Show(bool)
	{
	// true : Shows the path and it can be used
	// false : Shows the path and it cannot be used
	}

///*
	Path::Path()
	{
	//string pathID;
	// Default constructor, sets values to null
	pathID = "NULL";
	}

	
	Path::~Path()
	{
	// Default destructor
	}

	//*/
	

};
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
Interface file Paths.h, describes the class that is to be held in an array of the room class to determine which exits are available.

Description: A Room is a place in the virtual world where NPCs, creatures, players, items, stores/shops, 
weather, and many other things can exist. The room must be able to move an item to and from itself, 
collect garbage if items have been laying around too long, etc..


*/

#include "stdafx.h"

//#include "Paths.h"

class Path;

class Room
{
//*	
private:
	
	Path *_thisPath;

	std::string name;
	// The name of the room

	int locationX;
	// Holds the location of the x coordinate of the room

	int locationY;
	// Holds the location of the y coordinate of the room

	int locationZ;
	// Holds the location of the z coordinate of the room

	//Entity entityList[];
	// Array of objects holds a list of objects located in this object

	Path * pathsList[15];
	// Array of objects that holds the paths available for this room; the links to other rooms.

	std::string longDescription;
	// The rooms description, its visual appearance in words, stored in a string.
	
	std::string shortDescription;
	// The rooms description, its visual appearance in words, stored in a string.

//*/
public:

///*

	//***** Methods *****


	int getXLocation();
	// Returns the X location

	int getYLocation();
	// Returns the Y location

	int getZLocation();
	// Returns the Z location

	void setXLocation(int newXvalue);
	// sets the X location

	void setYLocation(int newYvalue);
	// sets the Y location

	void setZLocation(int newZvalue);
	// sets the Z location

//	void addEntity(Entity entityToAdd);
	// Adds the entity to the Rooms’s entityList[] array.

//	void removeEntity(Entity entityToRemove);
	// Removes an entity from the Room’s entityList[] array

	void addPath(Path * pathToAdd);
	// Check the database, or the map table, whatever, for the paths, and assign the paths to this room
	// adds the path to the pathList[] array

	void removePath(Path * pathToRemove);
	// Removes a path from the pathList[] array

	void setLocations();  //********     MAY NOT NEED       *******
	//  Check the database, or the map table, whatever, for the locations of rooms, and assign the x y z values

	void checkPath();
	// Call when a user is trying to move, or object is trying to be thrown (cool idea) in a certain direction:
	// check if there is a path in this direction and if it is navigable

	void setName(std::string);
	// sets this room's name

	std::string getName();
	// returns this room's name
	
	void setDescription(std::string longDescriptionToSet, std::string shortDescriptionToSet);
	// Set description of the long and short descriptions
	
	void setLongDescription(std::string longDescriptionToSet);
	// Set description of the long and short descriptions
	
	void setShortDescription(std::string shortDescriptionToSet);
	// Set description of the long and short descriptions

	std::string getLongDescription();
	// Set description of the long and short descriptions
	
	std::string getShortDescription();
	// Set description of the long and short descriptions
///*
	Room::Room();
		//Default Constructor
	
	Room::~Room();
		//Default destructor
//*/

};



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Implementation file Paths.h, describes the class that is to be held in an array of the room class to determine which exits are available.


*/

#include "stdafx.h"
#include "Paths.h"
//#include <string>

class Room
{
private:
	
	Path *_thisPath;

	std::string name;
	// The name of the room

	int locationX;
	// Holds the location of the x coordinate of the room

	int locationY;
	// Holds the location of the y coordinate of the room

	int locationZ;
	// Holds the location of the z coordinate of the room

	//Entity entityList[];
	// Array of objects holds a list of objects located in this object

	Path * pathsList[15];
	// Array of objects that holds the paths available for this room; the links to other rooms.

	std::string longDescription;
	// The rooms description, its visual appearance in words, stored in a string.
	
	std::string shortDescription;
	// The rooms description, its visual appearance in words, stored in a string.


public:



	//***** Methods *****//

	int getXLocation()
	{
	// Returns the X location
		return locationX;
	}

	int getYLocation()
	{
	// Returns the Y location
		return locationY;
	}

	int getZLocation()
	{
	// Returns the Z location
		return locationZ;
	}

	void setXLocation(int newXvalue)
	{
	// sets the X location
	}

	void setYLocation(int newYvalue)
	{
	// sets the Y location
	}

	void setZLocation(int newZvalue)
	{
	// sets the Z location
	}


//	void addEntity(Entity entityToAdd)	
//	{
	// Adds the entity to the Rooms’s entityList[] array.
//	}

//	void removeEntity(Entity entityToRemove)
//	{
	// Removes an entity from the Room’s entityList[] array
//	}



	void addPath(Path * pathToAdd)
	{
	// Check the database, or the map table, whatever, for the paths, and assign the paths to this room
	// adds the path to the pathList[] array
	}

	void removePath(Path * pathToRemove)
	{
	// Removes a path from the pathList[] array
	}

	void setLocations()
	{  //********     MAY NOT NEED       *******
	//  Check the database, or the map table, whatever, for the locations of rooms, and assign the x y z values
	}

	void checkPath()
	{
	// Call when a user is trying to move, or object is trying to be thrown (cool idea) in a certain direction:
	// check if there is a path in this direction and if it is navigable
	}

	void setName(std::string)
	{
	// sets this room's name
	}

	std::string getName()
	{
	// returns this room's name
		return name;
	}
	
	void setDescription(std::string longDescriptionToSet, std::string shortDescriptionToSet)
	{
	// Set description of the long and short descriptions
	}
	
	void setLongDescription(std::string longDescriptionToSet)
	{
	// Set description of the long and short descriptions
	}
	
	void setShortDescription(std::string shortDescriptionToSet)
	{
	// Set description of the long and short descriptions
	}

	std::string getLongDescription()
	{
	// Set description of the long and short descriptions
		return longDescription;
	}
	
	std::string getShortDescription()
	{
		return shortDescription;
	// Set description of the long and short descriptions
	}
///*
	Room::Room()
	{
		//Default Constructor
		shortDescription = "NULL";
		longDescription = "NULL";
	}


	Room::~Room()
	{
		//Default destructor
	}
	//*/
};

I think something went wrong when you pasted it. The names you give the files don't seem to match what's in them. And there's a .cpp file declaring a class.
im not sure what you mean about names of the files not matching unless you mean paths.cpp and path.h holding class path

as for the classes in the cpp file, i forgot that they were only supposed to contain the definitions and .h the declaration, illl fix that when i get home and see if that fixes my linking problem


thanks for your help, ill keep you updated

(sent with my phone, sorry for typos)
Interface file Paths.h, describes the class that is...

It says it's Paths.h, but then the file declares class Room. Class Room would belong in Room.h.
oh wow... i didnt notice, ill double check my code.. that would definitely produce some errors... i would think that would produce compiler errors though, my code may or may not be correct, thanks again, i get off work in a few hours =)
I checked my code.. the name mismatching was just a mistake in posting the code here.. nice catch though!


I removed the

class Room(and Path) {};

code from my .cpp files, then added the (Scope operator?)
 
Path::

and
 
Room::


and I generated 52 new errors..

I then realized the compiler had no idea what Room or Path was for these function definitions.. added

#include "Room.h"
and
#include "Paths.h"

to their corresponding .cpp files, and BAM!

Thank you very much for your help!
Topic archived. No new replies allowed.