»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 06-16-2003, 02:19 PM   #1 (permalink)
Registered User
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 2,946
nukes is on a distinguished road
Send a message via AIM to nukes Send a message via Yahoo to nukes
stupid class functions

I am trying to do 2 functions to modify variables in a class. They won't compile.
There are 2 ints, x and y. I am writing 1 function to return these values and 1 to set them:
Here's the functions:
Code:
int playerclass::get_position(p,q) 
   int *p, *q; {
   *p=X;
   *q=Y;
   return 0; }
 
/* for setting the player position at start of level.*/
int playerclass::set_position(p,q) 
   int q, p; {
   X=p;
   Y=q;
   return 0; }
Here's the class:
Code:
class playerclass
{ 
public:
int init();
int update_player();
/*int draw();*/
int get_position(p,q);
int set_position(p,q); 
private:
int centerx, centery;
int X, Y;
float dX, dY;
int health;
int mass;
};
and here's the error I get.
Code:
main.cpp:82: `p' was not declared in this scope
main.cpp:82: `q' was not declared in this scope
main.cpp:82: invalid data member initialization
main.cpp:82: (use `=' to initialize static data members)
main.cpp:83: `p' was not declared in this scope
main.cpp:83: `q' was not declared in this scope
main.cpp:83: invalid data member initialization
main.cpp: In member function `int playerclass::update_player()':
main.cpp:109: warning: assignment to `int' from `float'
main.cpp:109: warning: argument to `int' from `float'
main.cpp:110: warning: assignment to `int' from `float'
main.cpp:110: warning: argument to `int' from `float'
main.cpp:114: warning: assignment to `int' from `double'
main.cpp:114: warning: argument to `int' from `double'
main.cpp: At global scope:
main.cpp:120: `p' was not declared in this scope
main.cpp:120: `q' was not declared in this scope
main.cpp:121: `int playerclass::get_position' is not a static member of `class 
   playerclass'
main.cpp:121: initializer list being treated as compound expression
main.cpp:121: syntax error before `int'
main.cpp:123: ISO C++ forbids declaration of `q' with no type
main.cpp:123: `Y' was not declared in this scope
main.cpp:124: syntax error before `return'
main.cpp:127: `p' was not declared in this scope
main.cpp:128: `int playerclass::set_position' is not a static member of `class 
   playerclass'
main.cpp:128: initializer list being treated as compound expression
main.cpp:128: syntax error before `int'
main.cpp:130: ISO C++ forbids declaration of `Y' with no type
main.cpp:130: invalid conversion from `int*' to `int'
main.cpp:131: syntax error before `return'
What does this mean? Please help.
(I know what the things about floats and ints are, thats fine - not a problem)

__________________
_____
NuKeS
nukes is offline   Reply With Quote
Old 06-17-2003, 04:15 AM   #2 (permalink)
Registered User
 
Join Date: Jun 2003
Location: Reno
Posts: 20
choc101 is on a distinguished road
Well heres a couple quick things I noticed in the code provided.

How about this:

Code:
class playerclass
{ 
   public:
   player (); // Default Constructor
   int init();
   int update_player();
   /*int draw();*/
   int get_position(int, int); // What are the prurposes of p and q?
  /*int get_position(int*, int*); */ If you want them declared as pointers ( which I dont think you really need to)
   int set_position(int ,int ); 

   private:
   int centerx, centery;
   int X, Y; // What do X and Y represent?
   float dX, dY; 
   int health;
   int mass;
};
Code:
int playerclass::get_position( int* p, int* q ) 
{ 
    */int *p, *q; // Are these the same as the p and q passed in?
                         If they are they need to be defined as pointers 
                         otherwise use different variables.*/
    // What are you saying here?
    p=&X; // p = "address of" X
    q=&Y; // same
    return 0; // You might want to return the actual postion rather than true or false
}

int playerclass::set_position( p, q ) 
{
   X=p;
   Y=q;
   return 1; // Success? 
}
I could have misinterpreted what you are trying to accomplish. I just picked out some syntactical errors I noticed.
My C is a little rusty (especially pointers ) so I might not be totally 100% correct but it's a start.
Like I said I dont exactly what you are trying to do with the code so maybe you could give a little more detail so we might be able to clean up all the errors.

I also had a project a couple semesters back where we had to write a program that would simulate a basketball, football, soccer or whatever we wanted. So I might be able to help if thats what your doing.

Hopefully this cleans it up a little and helps you out
-Late
__________________
"Imagination is more important than knowledge..."
-Albert Einstein
choc101 is offline   Reply With Quote
Old 06-17-2003, 02:18 PM   #3 (permalink)
Registered User
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 2,946
nukes is on a distinguished road
Send a message via AIM to nukes Send a message via Yahoo to nukes
Sorry, I solved it. It turns out I had to define p and q about 10 times in different places to get it to work, thanks for replying though.
When I finish the project, or make some serious headway, I'll post the code.
__________________
_____
NuKeS
nukes is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 02:47 PM.