Results 1 to 6 of 6

Thread: C++: function definition does not declare parameters

  1. #1
    Join Date
    Dec 2008
    Location
    UK
    Beans
    438
    Distro
    Ubuntu 10.04 Lucid Lynx

    C++: function definition does not declare parameters

    I have this code:
    Code:
    241 class Ball{
    242     public:
    243     int x;
    244     int y;
    245     int yVel;
    246     int xVel;
    247     //The direction 1=right,up 2=right,down 3=left,up 4=left,down
    248     int dir;
    249     void SetP(int px, int py, SDL_Surface* bi);
    250     void draw();
    251     SDL_Rect box;
    252     SDL_Surface *image;
    253 };
    254 
    255 void Ball:SetP(int px, int py, SDL_Surface* bi){
    256     x = px;
    257     y = py;
    258     box.x = x;
    259     box.y = y;
    260     box.h = BALL_HEIGHT;
    261     box.w = BALL_WIDTH;
    262     image = bi;
    263 }
    when compiled:
    Code:
    matio@matio-desktop:~/Projects/SDL/BREAKOUT$ g++ -g breakout.cpp -o breakout -lSDL -lSDL_image -lSDL_ttf
    breakout.cpp:256: error: function definition does not declare parameters
    whats wrong?

  2. #2
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: C++: function definition does not declare parameters

    Perhaps you should try
    Code:
    void Ball::SetP(int px, int py, SDL_Surface* bi)
    instead of
    Code:
    void Ball:SetP(int px, int py, SDL_Surface* bi)

  3. #3
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: C++: function definition does not declare parameters

    Quote Originally Posted by matmatmat View Post
    I have this code:
    Code:
    241 class Ball{
    242     public:
    243     int x;
    244     int y;
    245     int yVel;
    246     int xVel;
    247     //The direction 1=right,up 2=right,down 3=left,up 4=left,down
    248     int dir;
    249     void SetP(int px, int py, SDL_Surface* bi);
    250     void draw();
    251     SDL_Rect box;
    252     SDL_Surface *image;
    253 };
    254 
    255 void Ball:SetP(int px, int py, SDL_Surface* bi){
    256     x = px;
    257     y = py;
    258     box.x = x;
    259     box.y = y;
    260     box.h = BALL_HEIGHT;
    261     box.w = BALL_WIDTH;
    262     image = bi;
    263 }
    when compiled:
    Code:
    matio@matio-desktop:~/Projects/SDL/BREAKOUT$ g++ -g breakout.cpp -o breakout -lSDL -lSDL_image -lSDL_ttf
    breakout.cpp:256: error: function definition does not declare parameters
    whats wrong?
    My C++ is a bit rough - but should you not be using "this" somewhere ?

    i.e.

    Code:
    255 void Ball:SetP(int px, int py, SDL_Surface* bi){
    256     this.x = px;
    257     this.y = py;
    258     this.box.x = x;
    259     this.box.y = y;
    260     this.box.h = BALL_HEIGHT;
    261     this.box.w = BALL_WIDTH;
    262     this.image = bi;
    263 }
    As otherwise the compiler will think that x,y, box and image are local variables (which aren't declared anywhere).
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  4. #4
    Join Date
    Dec 2008
    Location
    UK
    Beans
    438
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: C++: function definition does not declare parameters

    Thanks, I didn't notice there was only one ':'

  5. #5
    Join Date
    Nov 2005
    Beans
    33

    Re: C++: function definition does not declare parameters

    Quote Originally Posted by Tony Flury View Post
    My C++ is a bit rough - but should you not be using "this" somewhere ?

    i.e.

    Code:
    255 void Ball:SetP(int px, int py, SDL_Surface* bi){
    256     this.x = px;
    257     this.y = py;
    258     this.box.x = x;
    259     this.box.y = y;
    260     this.box.h = BALL_HEIGHT;
    261     this.box.w = BALL_WIDTH;
    262     this.image = bi;
    263 }
    As otherwise the compiler will think that x,y, box and image are local variables (which aren't declared anywhere).
    That is unnecessary, the compiler knows that x, y, etc are class variables. The only time you would have to use the "this" pointer in that way would be if the names of the method parameters conflicted with the names of class variables.

  6. #6
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: C++: function definition does not declare parameters

    Shows you how ropey my C++ is
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •