4 Replies - 1548 Views - Last Post: 24 July 2008 - 02:16 AM Rate Topic: -----

#1 ljfox4  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 67
  • Joined: 10-February 07

Function Prototype with Defaulting Arguments

Posted 23 July 2008 - 11:38 PM

I am using the following function:

void blitSurface(int x, int y, SDL_Surface* src, SDL_Surface* dest, SDL_Rect* clip = NULL)
{
...
}

Note that the last argument to this function defaults to NULL.
What would the function prototype need to look like to keep the compiler from thinking you don't have enough arguments when you allow the last argument to default to NULL?

Any help would be appreciated,
ljfox4

Is This A Good Question/Topic? 0
  • +

Replies To: Function Prototype with Defaulting Arguments

#2 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 117
  • View blog
  • Posts: 1,559
  • Joined: 25-January 07

Re: Function Prototype with Defaulting Arguments

Posted 24 July 2008 - 01:56 AM

You mean the thing you have posted doesn't work or like that? sorry, didn't got the question clearly.
Was This Post Helpful? 0
  • +
  • -

#3 ljfox4  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 67
  • Joined: 10-February 07

Re: Function Prototype with Defaulting Arguments

Posted 24 July 2008 - 02:04 AM

This function is declared towards the end of my file, so I need a function prototype towards the beginning. If my prototype says:


void blitSurface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*);

and later I do something like

blitSurface(0, 0, image, screen);

the compiler gives me an error stating

error: too few arguments to function ‘void blitSurface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*)

How can I correct this behavior?
Was This Post Helpful? 0
  • +
  • -

#4 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 117
  • View blog
  • Posts: 1,559
  • Joined: 25-January 07

Re: Function Prototype with Defaulting Arguments

Posted 24 July 2008 - 02:08 AM

Oh I got it. keep it same as your definition void blitSurface(int x, int y, SDL_Surface* src, SDL_Surface* dest, SDL_Rect* clip = NULL); it works fine.
Was This Post Helpful? 0
  • +
  • -

#5 ljfox4  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 67
  • Joined: 10-February 07

Re: Function Prototype with Defaulting Arguments

Posted 24 July 2008 - 02:16 AM

I got the following errors:

main.cpp: In function ‘void blitSurface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*)’:
main.cpp:363: error: default argument given for parameter 5 of ‘void blitSurface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*)’
main.cpp:16: error: after previous specification in ‘void blitSurface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*)’



line 363 is the function definition and reads:

void blitSurface(int x, int y, SDL_Surface* src, SDL_Surface* dest, SDL_Rect* clip = NULL)
{
...
}

line 16 is the prototype and reads
void blitSurface(int x, int y, SDL_Surface* src, SDL_Surface* dest, SDL_Rect* clip = NULL);


Any thoughts as to why your method caused problems? I don't see why it is complaining that I utilized the default argument.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1