Jump to content
  • Advertisement
Sign in to follow this  
Gegenki

insane linker error

This topic is 3653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a header file called mouse.h
class Mouse
{
	static int X;
	static int Y;
public:
	static int Initialise(HWND);
	static int Update(LParam);
protected:
	static int XPos();
	static int YPos();
};
and a cpp file called mouse.cpp Most thigns in it work. Initialise starts it up Update gets the raw information from the mouse and fills the variable LastX (found in mouse.cpp) with the change in mouse position. XPos and YPos should update the X and Y values seen above but I can't figure out how to access them from the cpp file without causing link errors. This is what I would have already so it would look something like this but without the link errors -
	int Mouse::XPos()
	{
		Mouse::X = Mouse::X + LastX;
		return Mouse::X;
	}

Share this post


Link to post
Share on other sites
Advertisement
You haven't actually said what the error is. I assume it's because you haven't provided a definition of your variables. Add the following to Mouse.cpp:

int Mouse::X = 0;
int Mouse::Y = 0;

Share this post


Link to post
Share on other sites
post the linker errors?

Best guess; you forgot to instantiate the static member vars in the cpp. Something like:

int Mouse::X = 0;
int Mouse::Y = 0;

Edit: arg, beaten by EvilSteve

Share this post


Link to post
Share on other sites
A class with all static members isn't a class. I think what you might be looking for is a namespace. Of course, your use of "protected" seems to imply that there could be an inheritance relationship there, which makes little sense given your current class setup.

Can you describe what you are trying to achieve?

Share this post


Link to post
Share on other sites
excellent intialising it worked perfectly.
Thankyou

WHat do you mean about them all being static makes it not a class.
If I don't use static I get error C2352

A static member function called a nonstatic member function. Or, a nonstatic member function was called from outside the class as a static function.

If I make update non static it will give me the error as it is called from main.cpp

case WM_INPUT:
{
Mouse::Update(Param2);


If I make XPos or YPos nonstatic it throws the same error as the calling function (update) is static.

I think I understand what you mean, I should be able to make lots of calls to the same class and they run seperately to each other and anything static coexists between them but as I say, I'm getting these errors due to the mismatch of static and nonstatic

Share this post


Link to post
Share on other sites
Quote:
Original post by Gegenki
excellent intialising it worked perfectly.
Thankyou

WHat do you mean about them all being static makes it not a class.
If I don't use static I get error C2352

A static member function called a nonstatic member function. Or, a nonstatic member function was called from outside the class as a static function.


Classes are used to define a data type.

What is an int? A variable that represents a number.
What is a std::string? A variable that represents a piece of text.
Now, what is a Mouse? A variable... hmm. That doesn't seem right, does it? You have a set of functionality that relates to the mouse, but it doesn't make sense for you to talk about a mouse.

Well, that's not what classes are for.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!