Class member function not recognized??

This is a discussion on Class member function not recognized?? within the C++ Programming forums, part of the General Programming Boards category; Hi everybody, recently I've been working on getting a simple gravity program where a spaceship orbits around a sun going, ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    6

    Class member function not recognized??

    Hi everybody, recently I've been working on getting a simple gravity program where a spaceship orbits around a sun going, I've almost completed it but I've hit a roadblock.

    Whenever I compile it says

    13 C:\Dev-Cpp\Mission Space rev2\C-SpaceShip.cpp expected `;' before '(' token

    and that

    29 C:\Dev-Cpp\Mission Space rev2\Body.cpp 'class SpaceShip' has no member named 'Update'

    I know it something very simple that's wrong with the function Update in my class, can anyone help me figure it out?

    Code:
    #include "math.h"
    class SpaceShip
    {
          public:
                 long int mass;
                 int locX;
                 int locY;
                 int imageheight;
                 int imagewidth;
                 long int velocityX;
                 long int velocityY;             
                 SDL_Rect dest, source;
                 int Update (Planet *pEarth, SDL_Surface *Red, SDL_Surface *screen)
                 {
                               int distance;
                               int forceX;
                               int forceY;
                               long int masses;
                               long int GravVector;
                               long int accelX;
                               long int accelY;
                               distance = sqrt(((*pEarth.dest.x - locX * *pEarth.dest.x - locX) + (*pEarth.dest.y - locY * *pEarth.dest.y - locY))); // this is the distance formula
                               forceX = distance * distance;//these lines are used to square distance
                               distance = forceX;//this is also
                               forceX = 0;//this is the last one
                               masses = (*pEarth.mass * mass);
                               GravVector = masses/distance;//distance is already squared here
                               forceX = GravVector/(*pEarth.dest.x - locX);//normalizes vector into x and y forces instead of vector force, GravVector is a force.
                               forceY = GravVector/(*pEarth.dest.y - locY);
                               accelX = forceX/mass;
                               accelY = forceY/mass;
                               velocityX = velocityX + accelX;//velocity is part of class data not definded in this function
                               velocityY = velocityY + accelY;
                               dest.x = dest.x + velocityX;
                               dest.y = dest.y + velocityY;
                               BlitSurface(Red,source,screen,dest);
                               SDL_UpdateRect(dest.x,dest.y,dest.w,dest.h);
                               return 0;
                               }; 
                 SpaceShip(int parmass, int locationX, int locationY, int parimageW, int parimageH )
                 {
                               velocityX = 0;
                               velocityY = 0;     
                               mass = parmass;
                               locY = locationY;
                               locX = locationX;
                               imageheight = parimageH;
                               imagewidth = parimageW;
                               
                               dest.x = locX;
                               dest.y = locY;
                               dest.h = imageheight;
                               dest.w = imagewidth;
                               
                               source.x = 0;
                               source.y = 0;
                               source.h = imageheight;
                               source.w = imagewidth;
                               return;
                               }
                 
                               };//end of class

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I see some non-standard types in there. What's in "math.h"?
    If SDL_Rect, Planet, SDL_Surface... aren't defined in "math.h" then you forgot to #include the appropriate headers.

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Code:
                 int Update (Planet *pEarth, SDL_Surface *Red, SDL_Surface *screen)
                 {
                               int distance;
                               int forceX;
                               int forceY;
                               long int masses;
                               long int GravVector;
                               long int accelX;
                               long int accelY;
                               distance = sqrt(((*pEarth.dest.x - locX * *pEarth.dest.x - locX) + (*pEarth.dest.y - locY * *pEarth.dest.y - locY))); // this is the distance formula
                               forceX = distance * distance;//these lines are used to square distance
                               distance = forceX;//this is also
                               forceX = 0;//this is the last one
                               masses = (*pEarth.mass * mass);
                               GravVector = masses/distance;//distance is already squared here
                               forceX = GravVector/(*pEarth.dest.x - locX);//normalizes vector into x and y forces instead of vector force, GravVector is a force.
                               forceY = GravVector/(*pEarth.dest.y - locY);
                               accelX = forceX/mass;
                               accelY = forceY/mass;
                               velocityX = velocityX + accelX;//velocity is part of class data not definded in this function
                               velocityY = velocityY + accelY;
                               dest.x = dest.x + velocityX;
                               dest.y = dest.y + velocityY;
                               BlitSurface(Red,source,screen,dest);
                               SDL_UpdateRect(dest.x,dest.y,dest.w,dest.h);
                               return 0;
                               }; 
    Not sure if that's your only problem, but there should be no semicolin there. (Unless I'm missing something and Update() and SpaceShip() are two seperate classes.)
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If my counting isn't too far off,
    Code:
    SDL_Rect dest, source;
    is line 12 - usuall when it says "missing semicolon", there is something wrong with the line(s) before the error, and the reason the compiler says missing semicolon is just that it's "derailed"[1]. I think cpjust is on the right track: SDL types are not declared, so the compiler doesn't know what SDL_Rect is, and from then on, it's just confused and can't figure out what's going on.

    Blackroot: The semicolon there is harmless - it's not needed, but it's allowed.

    [1] I use the term "derailed", but "took the wrong turning" may be a better analogy. If you think of it like someone giving you directions, something like "Turn right at the big tree, then the second left, etc, etc". Unfortunately, unknown to the director, the big tree was taken down last night, so you miss the turning to the right, and turn right another mile down the road (at a differnet tree). Of course, now any further instructions would probably get you even more lost than you already are, and the further you go, the more confusing it gets. Likewise, the compiler is looking for certain "landmarks". If it misses one landmark [because it doesn't understand what is going on], it just gets even more confusing as it goes along - although sometimes it sort of gets back to the right track for a while, and then things go horribly wrong again.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    5,883
    Quote Originally Posted by Blackroot View Post
    Not sure if that's your only problem, but there should be no semicolin there.
    The semi-colon is allowed "there" although it is optional and may be removed.

    The problem, as cpjust has noted, is probably related to usage of types that have not been defined (SDL_Rect, etc). And "math.h" should be either <math.h> or <cmath>, although some compilers will resolve a "math.h" header by looking in system locations.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 10:34 PM
  5. Is it possible to have callback function as a class member?
    By Aidman in forum Windows Programming
    Replies: 11
    Last Post: 08-01-2003, 11:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21