home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

stupid class functions

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1911
Discussions: 200,976, Posts: 2,379,814, Members: 246,340
Old June 16th, 2003, 05:19 PM   Digg it!   #1
Ultimate Member
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 3,221
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 June 17th, 2003, 07:15 AM     #2
Junior Member
 
Join Date: Jun 2003
Location: Reno
Posts: 20
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
choc101 is offline   Reply With Quote
Old June 17th, 2003, 05:18 PM     #3
Ultimate Member
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 3,221
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 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Health Care Rationing (8)
Is It Just Me? (3062)
Charges against non-tippers dropped.. (13)
Delete an OS (16)
Nvidia GTX 260 problem (9)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
windows vista security holes (18)
Regular Build (11)
Point and Shoot Camera Suggestions. (7)
windows 7 problem (7)
Internet Lost (5)
Multiple Restarts Required at Boot (5)
Recent Discussions
C# + LINQ Help (7)
windows vista security holes (18)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (38)
Nvidia GTX 260 problem (9)
Dynex DX E-402 (3)
EVGA 9800 gtx help with finding a goo.. (12)
Multiple Restarts Required at Boot (5)
Point and Shoot Camera Suggestions. (7)
Delete an OS (16)
cell phone won't work (0)
Is the PSU I received dead? (15)
Can't open Word (12)
Steam ID's, Gamertags etc... (4)
Games, Cables, PCI cards, and more fo.. (6)
Dept. of HS: NSA 'Helped' Develop Vis.. (17)
Linksys WMP54GS wireless card problem.. (5)
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)
Browsers wont load websites (3)
help me pls laptop just stopped worki.. (0)
Open With ..... Win7 (3)
Laptop with wireless problem. (12)
Internet Lost (5)
virus blocking exe. files (1)
CPU fan stops spinning randomly (11)


All times are GMT -4. The time now is 12:36 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.