error LNK2019: unresolved external symbol "

Hi, I have got a problem on my hand.

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
#ifndef ELEMENTAL_H
#define ELEMENTAL_H

#include "SDL_init.h"
#include "Sprite.h"


class Elemental: public Game::Sprite{
public: 
	Elemental( SDL_Surface* img, int x, int y );

	//virtual ~Sprite();			// Destructor.
	void tick();					// Loop which controls and updates a specific sprite object with the background objects.
	
	SDL_Surface* get_image();

	double getSpeed_X();			// Will get the speed ( x ) of the object
	double getSpeed_Y();			// Will get the speed ( y ) of the object
	
	void set_speed( double x, double y );	// Will set the speed ( x ) of the object
	
	void move(); // Will be in main class
	void show(); // Will be in main class

	void install_sprite( std::string filename );
	void delete_sprite();
	
protected:

private:
	double speed_x, speed_y, x_pos, y_pos;
	SDL_Surface* sprite_image;
	SDL_Rect ebox;
	
};

#endif 



Sprite
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
/*********************************************************
This is the root class for all gameobjects.

**********************************************************/
#ifndef SPRITE_H
#define SPRITE_H

#include "SDL_init.h"
#include <string>

const int SPRITE_WIDTH = 50;
const int SPRITE_HEIGHT = 56;

namespace Game
{
class Sprite
{
public:
	Sprite();
	Sprite( std::string filename );				// Constructor.
	Sprite::Sprite( SDL_Surface* img );

	//virtual ~Sprite();		// Destructor.
	virtual void tick();		// Loop which controls and updates a specific sprite object with the background objects.
	SDL_Surface* get_image();

	double getPos_X();				// Will get the x position of the object
	double getPos_Y();				// Will get the y position of the object
	double getSpeed_X();			// Will get the speed ( x ) of the object
	double getSpeed_Y();			// Will get the speed ( y ) of the object
	
	void move_sprite(double x, double y );	// Moves the sprite object to a specific position.
	void move();
	void show();
	void set_pos( double x, double y );// Will set the position ( x ) of the object
	void set_speed( double x, double y );	// Will set the speed ( x ) of the object

	void install_sprite( /*Sprite* installed,*/ std::string filename );
	void delete_sprite( /*Sprite* deleted */);
	
	//Sprite* getInstance();			// Will create a neW sprite object and place it on the screen.
	

protected:
	//Sprite() {};

private:
	double speed_x, speed_y, x_pos, y_pos;
	SDL_Surface* sprite_image;
	SDL_Rect box;
	bool jumped;
};

}
#endif 


Last edited on
closed account (zb0S216C)
You've forgotten about your Game namespace within the first file. If should be:

1
2
3
4
class Elemental: public Game::Sprite
{
    // ...
};


Wazzak
thanks, that helped- but now I got another problem with unresolved external symbol

Elemental.obj : error LNK2019: unresolved external symbol "public: __thiscall Game::Sprite::Sprite(void)" (??0Sprite@Game@@QAE@XZ) referenced in function "public: __thiscall Elemental::Elemental(struct SDL_Surface *,int,int)" (??0Elemental@@QAE@PAUSDL_Surface@@HH@Z)
closed account (zb0S216C)
Have you defined the body for Game::Sprite::Sprite( )? If so, can you post it?

Wazzak
Last edited on
no its not defined, should it be defined ??
closed account (zb0S216C)
Yes. Before compilation takes place, all functions and classes should complete.

Wazzak
well okey i will give u some code to help with the problem

Sprite.h
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
/*********************************************************
This is the root class for all gameobjects.

**********************************************************/
#ifndef SPRITE_H
#define SPRITE_H

#include "SDL_init.h"
#include <string>

const int SPRITE_WIDTH = 50;
const int SPRITE_HEIGHT = 56;

namespace Game
{
class Sprite
{
public:
	Sprite();
	Sprite( std::string filename );				// Constructor.
	Sprite::Sprite( SDL_Surface* img );

	//virtual ~Sprite();		// Destructor.
	virtual void tick();		// Loop which controls and updates a specific sprite object with the background objects.
	SDL_Surface* get_image();
	void set_image( SDL_Surface* image );
	double getPos_X();				// Will get the x position of the object
	double getPos_Y();				// Will get the y position of the object
	double getSpeed_X();			// Will get the speed ( x ) of the object
	double getSpeed_Y();			// Will get the speed ( y ) of the object
	
	void move_sprite(double x, double y );	// Moves the sprite object to a specific position.
	virtual void move();
	void show();
	void set_pos( double x, double y );// Will set the position ( x ) of the object
	void set_speed( double x, double y );	// Will set the speed ( x ) of the object

	void install_sprite( /*Sprite* installed,*/ std::string filename );
	void delete_sprite( /*Sprite* deleted */);
	
	//Sprite* getInstance();			// Will create a neW sprite object and place it on the screen.
	

protected:
	//Sprite() {};

private:
	double speed_x, speed_y, x_pos, y_pos;
	SDL_Surface* sprite_image, optimized_image;
	SDL_Rect box;
	bool jumped;
};

}
#endif 


Sprite.cpp
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
#include "Sprite.h"



namespace Game
{
	Game::Sprite::Sprite(void){}
	


	Sprite::Sprite( std::string filename )
	{
		sprite_image = IMG_Load( filename.c_str() );
		
		//Set position
		//x_pos = 0;
		//y_pos = 0;
		
		//Set speed
		speed_x = 0;
		speed_y = 0;
		
		//Set the collisionbox
		box.x = x_pos;
		box.y = y_pos;
		box.w = 50;
		box.h = 56;

	}

	Sprite::Sprite( SDL_Surface* img )
	{
		sprite_image = img;
		//sets all variables to zero.
		/*this->x_pos = 0;
		this->y_pos = 500;*/
		this->speed_x = 0;
		this->speed_y = 0;

		//Set the collisionbox
		box.x = x_pos;
		box.y = y_pos;
		box.w = 50;
		box.h = 56;

	}

	SDL_Surface* Sprite::get_image()
	{
		return sprite_image;
	}

	void Sprite::install_sprite( /*Sprite* installed,*/ std::string filename )
	{	
		this->x_pos = 0;
		this->y_pos = 0;
		this->speed_x = 0;
		this->speed_y = 0;
		// Loads the image doubleo the sprite object.
		this->sprite_image = IMG_Load( filename.c_str() );
	}

	void Sprite::delete_sprite(/* Sprite* deleted */)
	{
		// If not then delete its surface and
			// then delete the object.
			SDL_FreeSurface( this->sprite_image );
			delete this;
		
	}

	/*Sprite* Sprite::getInstance()
	{
		return new Sprite();
	}*/

	

	/*
	void Sprite::Move( double x, double y )
	{
		this->x_pos = x, this->y_pos = y;
	}*/


	double Sprite::getPos_X()
	{
		return this->x_pos;
	}

	double Sprite::getPos_Y()
	{
		return this->y_pos;
	}

	double Sprite::getSpeed_X()
	{
		return this->speed_x;
	}
	
	double Sprite::getSpeed_Y()
	{
		return this->speed_x;
	}

	void Sprite::set_pos( double x, double y )
	{
		this->x_pos = x;
		this->y_pos = y;
	}

	void Sprite::set_speed( double x, double y )
	{
		this->speed_x = x;
		this->speed_y = y;
	}
	
	
}


Elemental.h
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
#ifndef ELEMENTAL_H
#define ELEMENTAL_H

#include "SDL_init.h"
#include "Sprite.h"


class Elemental: public Game::Sprite{
public: 
	Elemental();
	Elemental( SDL_Surface* img, int x, int y );

	//virtual ~Sprite();			// Destructor.
	void tick();					// Loop which controls and updates a specific sprite object with the background objects.
	
	SDL_Surface* get_image();

	double getSpeed_X();			// Will get the speed ( x ) of the object
	double getSpeed_Y();			// Will get the speed ( y ) of the object
	
	void set_speed( double x );	// Will set the speed ( x ) of the object
	
	
	int init( std::string filename, SDL_Surface* dest );
	void draw();


	void move(); // Will be in main class
	void show(); // Will be in main class

	void install_sprite( std::string filename );
	void delete_sprite();
	
protected:
	
private:
	double speed_x, x_pos, y_pos;
	int isPainted;
	SDL_Surface* sprite_image;
	SDL_Surface* escreen;
	SDL_Rect ebox;
	
};

#endif 


Elemental.cpp
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
#include "Elemental.h"

Elemental::Elemental( SDL_Surface* img, int x, int y )
{
	sprite_image = img;

	x_pos = x;
	y_pos = y;

	ebox.x = x_pos;
	ebox.y = y_pos;
	ebox.w = 40;
	ebox.h = 40;

}

void Elemental::tick()
{

	
	int x;
		if( x = 0  && x < 75 ) 
		{
			speed_x++;
			if( speed_x > 2 && speed_x > 0 ) 
				for( int i =2; i = 0; i -- )
					speed_x--;		

			ebox.x = speed_x;
		}else
			while( x > 0 )
			{
				speed_x--;
				ebox.x -= speed_x;
			}
			
		x++;
		
}

SDL_Surface* Elemental::get_image()
{
	return sprite_image;
}

void Elemental::set_speed( double x )
{
	speed_x = x;

}

void Elemental::delete_sprite()
{
	SDL_FreeSurface(sprite_image);
}

int Elemental::init( std::string filename, SDL_Surface* dest )
{
	sprite_image = IMG_Load( filename.c_str() );
	escreen = dest;
	return 0;
}

void Elemental::draw()
{
	if(isPainted==0) isPainted=1;

	SDL_Rect dest;
	dest.x = (int)x_pos;
	dest.y = (int)y_pos;

	SDL_BlitSurface( sprite_image, NULL, escreen, &dest );

}


Need any more code tell me.

thanks

by the way the problem is:

GameEngine.obj : error LNK2019: unresolved external symbol "public: __thiscall Elemental::Elemental(void)" (??0Elemental@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'enemies''(void)" (??__Eenemies@@YAXXZ)
closed account (zb0S216C)
You haven't defined the body of your default constructor for Element. Since you declared a default constructor (Elemental::Elemental( )), you've over-ridden the default constructor provided by the complier. When you override a constructor or destructor, must define its body, no questions asked.

Wazzak
Last edited on
yeah but when i didnt had any default constructor in Element, then it said that i need to have one :S
closed account (zb0S216C)
I'm sorry, I should have explained it properly. When a user-defined constructor is declared, you override the default constructor, meaning that the compiler doesn't provide a constructor. Instead, the compiler will use the user-defined constructor, not the default one. This is the same for the destructor.

There's a general rule that you should follow: Always declare a constructor without parameters (equivalent to void) if appropriate.

Wazzak
Last edited on
okey so it shoulb be like I have now ? well with this is Elemental.cpp:

Elemental::Elemental(void) {}
closed account (zb0S216C)
Yes, exactly. Of course, void is optional; you can leave the parentheses blank if you wish.

Wazzak
okey thanks =)
Topic archived. No new replies allowed.