Linker Errors

I have these two classes, where Delivery is multiply dependent on Coord. The goal I'm aiming for is so that Delivery will have #include "Coord.h" on top. Somehow when I do that It gives out a bunch of Linker errors saying undefined reference to Coord::Coord(). However, putting in #include "Coord.cpp" on top fixes the thing. I dont want that. How come it doesnt work?

EDIT: Edited using Zaita's find

DELIVERY SOURCE
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 DELCPP
#define DELCPP
#include "Delivery.h"

using namespace std;

Delivery::Delivery(void){}

Delivery::Delivery(string &name, Coord::Coord &loc){
	this->location = loc;
	this->name = name;
}
void Delivery::setName(string &name){
	this->name = name;
}
string Delivery::getName(){
	return this->name;
}
void Delivery::setLocation(Coord::Coord &loc){
	this->location = loc;
}
Coord Delivery::getLocation(){
	return this->location;
}
string Delivery::toString(){
	string temp = this->name;
	temp = temp.append(this->location.toString());
	return temp;
}
#endif 

DELIVERY 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
#ifndef DEL
#define DEL
#include "Coord.h"

using namespace std;

class Delivery
{
public:
	Delivery( void );
		
        Delivery( string &name, Coord::Coord &loc );
        
        void setName( string &name );
        	
        void setLocation( Coord::Coord &loc );
        	
        string getName();
        	
        Coord getLocation();
        	
        string toString();
        
private:
        string name;
        Coord::Coord location;
};
#endif 


COORD 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
31
32
33
#ifndef COORD
#define COORD
#include <string>

using namespace std;

class Coord
{
public:
        Coord( void );
       	
        Coord( int x, int y );
        	
        void setX( int x );
        
        void setY( int y );
        
        int getX();
        	        
        int getY();
        	
        void setGridSize( int size );
        
        int getGridSize();
       
        string toString();
        
private:
        int x;
        int y;
        int gridSize;		
};
#endif 


COORD SOURCE
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
#ifndef COORDCPP
#define COORDCPP
#include <sstream>
#include "Coord.h"

using namespace std;

Coord::Coord( void ){}

Coord::Coord(int x, int y){
        Coord::setGridSize(25); //default grid size

	if ( (x > this->gridSize) || (y > this->gridSize) ) //if coordinate is more than grid, set to HQ coords
	{
		x = 10;
		y = 20;
	}
	if ( (x < 0) || (y <0 ) ) //if coordinates are <0 set to HQ coords
	{
		x = 10;
		y = 20;
	}
	
	this->x = x;
	this->y = y;
}
void Coord::setX(int x){
	if( (x < this->gridSize) && (x>0))
		this->x = x;
}
void Coord::setY(int y){
	if( (y < this->gridSize) && (y>0))
		this->y = y;
}
int Coord::getX(){
	return this->x;
}
int Coord::getY(){
	return this->y;
}
void Coord::setGridSize(int gridsize){
	this->gridSize = gridsize;
}
int Coord::getGridSize(){
	return this->gridSize;
}
string Coord::toString(){
	stringstream x(""), y("");
	string coord;
	x << this->x;
	y << this->y;
	coord = x.str().append(", ");
	coord = coord.append(y.str());
	return coord;
}
#endif
Last edited on
Delivery source, Line 22:
1
2
3
Coord::Coord Delivery::getLocation(){
	return this->location;
}


Should be:
1
2
3
Coord Delivery::getLocation(){
	return this->location;
}


As should your definition in the class.
Thanks for that. Code has been edited. However, the Linker errors are still there. Anymore mistakes you noticed?
Topic archived. No new replies allowed.