Sign in to follow this  
Gegenki

insane linker error

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this