• Create Account

## error lnk2001

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1littletray26  Members

Posted 10 March 2013 - 09:18 PM

Hey GameDev

Just a quick one today, I can't seem to figure out why this code:


#include <d3d9.h>
#include <d3dx9.h>

#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

class Player
{
private:

public:
static void Initialize(LPDIRECT3DDEVICE9* d3dDevice);
static void Draw(LPD3DXSPRITE sprite, LPDIRECT3DTEXTURE9* texture);
static void Update();
};

void Player::Initialize(LPDIRECT3DDEVICE9* d3dDevice)
{
}

void Player::Draw(LPD3DXSPRITE sprite, LPDIRECT3DTEXTURE9* texture)
{
}

void Player::Update()
{

}


Feels like telling me this:

Error 1 error LNK2001: unresolved external symbol "private: static struct tagRECT Player::paddleTexture" (?paddleTexture@Player@@0UtagRECT@@A)

Error 2 error LNK2001: unresolved external symbol "private: static struct D3DXVECTOR3 Player::paddlePosition" (?paddlePosition@Player@@0UD3DXVECTOR3@@A)

Could I get one of you lovely people to help me out?

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

### #2Zaoshi Kaba  Members

Posted 11 March 2013 - 01:45 AM

So far you only declared static variables, but didn't define them, to fix that add this in your source file:

D3DXVECTOR3 Player::paddlePosition;
RECT Player::paddleTexture;

### #3littletray26  Members

Posted 11 March 2013 - 08:41 AM

Thank you Zaoshi, that fixed it

Would you, or anyone else, mind explaining for myself, and anyone else with the same problem, Why I need to do this, and also where I should put it? I just put that code into the global scope (outside the class or functions), is there a better place?

I find it's easier for myself to learn, and remember, if I understand why and how

Thanks again!

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

### #4EWClay  Members

Posted 11 March 2013 - 09:32 AM

There's not much more to add. In C++ you have to define variables before you can use them, and a static class member is only declared inside the class definition, otherwise you would end up with one in every source file that included it.

The real question is why you are using static variables. If all the statics were removed, the variables would live inside the player object and there would be no need to define them separately.

### #5Khatharr  Members

Posted 11 March 2013 - 07:48 PM

EWClay, on 11 Mar 2013 - 08:39, said:
There's not much more to add. In C++ you have to define variables before you can use them, and a static class member is only declared inside the class definition, otherwise you would end up with one in every source file that included it.

The real question is why you are using static variables. If all the statics were removed, the variables would live inside the player object and there would be no need to define them separately.

This.

You need to look at what the 'static' keyword actually does when you use it within a class. It seems like you're trying to create a singleton and just going about it in entirely the wrong way. An easy solution to that is: do not use a singleton here. Typically you should avoid singletons whenever possible.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

### #6littletray26  Members

Posted 12 March 2013 - 04:23 AM

ou need to look at what the 'static' keyword actually does when you use it within a class.

I have reasons for wanting them to be static, and I do know what the static keyword does. Thanks.

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

### #7NightCreature83  Members

Posted 12 March 2013 - 06:21 AM

ou need to look at what the 'static' keyword actually does when you use it within a class.

I have reasons for wanting them to be static, and I do know what the static keyword does. Thanks.

Then what is that reason because you have just made it so that you can never add a second local player without changing that class if you want him to control a separate paddle.

There is usually no good reason to use a static member variable unless it's a piece of data that needs to be the same for all instances to work.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max

### #8Khatharr  Members

Posted 12 March 2013 - 11:50 PM

ou need to look at what the 'static' keyword actually does when you use it within a class.

I have reasons for wanting them to be static, and I do know what the static keyword does. Thanks.

Not trying to jump on you there. My post sounded a bit harsh and I didn't intend that. I was just trying to express that 'static' behaves differently within a class declaration than it does in other places.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

### #9littletray26  Members

Posted 13 March 2013 - 11:07 PM

Not trying to jump on you there. My post sounded a bit harsh and I didn't intend that. I was just trying to express that 'static' behaves differently within a class declaration than it does in other places.

ou need to look at what the 'static' keyword actually does when you use it within a class.

I have reasons for wanting them to be static, and I do know what the static keyword does. Thanks.

Then what is that reason because you have just made it so that you can never add a second local player without changing that class if you want him to control a separate paddle.

There is usually no good reason to use a static member variable unless it's a piece of data that needs to be the same for all instances to work.

l'm sorry if the way I responded sounded a bit rude. You're both right though, although I do know what the static keyword does, I've no idea what I was thinking putting it there.

Thank you both for helping me resolve the problem, and more

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.