Advertisement

Classes Problem

Started by January 22, 2004 04:38 AM
9 comments, last by Ructions 21 years, 1 month ago
I am using VC++. and am making an arkanoid game. i am setting up classes for my paddle, ball etc. i am having problems accessing the varible that i have put in the class. i am getting an unresolved external symbol. i only what to access the varibles in the fuctions in the class. my header file looks like this #ifndef paddleh_h #include <windows.h> // Header File For Windows #include <stdio.h> // Header File For #include <gl\gl.h> // Header File For The #include <gl\glu.h> // Header File For The #include <gl\glaux.h> // Header File For The Glaux #include <math.h> class Paddle { private: private float paddle_xpos; // Position components public: Paddle(); ~Paddle(); //Protypes static void UpdatePaddlePosition(float); static float GetPaddlePosition(void); static void DrawPaddle(float); static float LimitPaddleMovement(float); static void ResetPaddle(void); static void SpeedUpPaddle(void); static void SlowDownPaddle(void); }; #endif my .ccp file looks like this.. #include "paddleh.h" float Paddle::LimitPaddleMovement(float xpos) { if (xpos/*+BatWidth*/>=7.7) { xpos=7.7/*-BatWidth*/; } if (xpos/*-BatWidth*/<=-9.7) { xpos=/*BatWidth-*/-9.7; } return(xpos); } void Paddle::DrawPaddle(float xpos) { glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(2.0f + xpos , 0.0f, 0.0f);//bottom right glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.0f + xpos , 0.0f, 0.0f);//bottom left glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.0f + xpos , -0.5f, 0.0f);//top left glTexCoord2f(0.0f, 0.0f); glVertex3f(2.0f + xpos , -0.5f, 0.0f);//top right glEnd(); // Done Drawing The Quad return; } void Paddle::UpdatePaddlePosition(float xpos) { if (xpos<0) Paddle:addle_xpos += xpos; else Paddle:addle_xpos -= xpos; return; } float Paddle::GetPaddlePosition(void) { return(Paddle:addle_xpos); //return(2); } any help would be greatful.
Any special reason why all methods in that class are static ?
You can not access non-static member variables from a static context.
Advertisement
No not at all.
Looks a little too Java-like for C++.

---
K-1 Productions: Come visit us here.
---K-1 Productions: Come visit us here.
um... have you used either of those languages?
Well I havn''t done any programming in C++ in ages but this seems strange to me -

class Paddle
{
private:
private float paddle_xpos; // Position components
....
....

why is the variable defined as private?
Its already private to the class so maybe try taking out the private declaration before the variable type.

I could be wrong though.
Advertisement
maybe you forgot:

#ifndef ....
#define ....



#endif
belgrade-yu
What i think, that a ''static float'' function is not seen as a ''float'' function so the compiler looks in the cpp files for a static float Paddle::LimitPaddleMovement(float) function and doesn''t find it. Try removing the static at the declarations or add static at the definentions of the functions, also the private keyword used at the declaration of the variable paddle_xpos is totally unneccesary.
I tryed that but its still not working. i just learning C++ so is there any good websites to look up. to help with this problem.
quote:
Original post by Ructions
I tryed that but its still not working. i just learning C++ so is there any good websites to look up. to help with this problem.


Your function has been defined as static.
Static functions can''t access non-static members IIRC.

Remove the static in front of your function prototypes or change "float paddle_xpos;" to "static float paddle_xpos;"

Cheers
Dan
Lead...Pro..Armathing.

This topic is closed to new replies.

Advertisement