SDL Error: redefinition of default parameter

Nov 22, 2008 at 3:09am
Hey Guys,

Just started a basic SDL program but I've already come to an error after the first couple of minutes. Not exactly sure why I'm getting the error though. Anyway here is my source and the error.

The error itself i gather relates to the last 2 chunks of code on this post. I know there are a lot of un-used variables, but thats because i'll be using them soon :P

ERROR:

1>------ Build started: Project: SDL_FIRST_RUN, Configuration: Debug Win32 ------
1>Compiling...
1>graphix.cpp
1>c:\documents and settings\scottie\my documents\visual studio 2005\projects\sdl_first_run my game -using tiling engine\sdl_first_run\graphix.cpp(41) : error C2572: 'apply_surface' : redefinition of default parameter : parameter 5
1> c:\documents and settings\scottie\my documents\visual studio 2005\projects\sdl_first_run my game -using tiling engine\sdl_first_run\graphix.h(9) : see declaration of 'apply_surface'
1>Build log was saved at "file://c:\Documents and Settings\Scottie\My Documents\Visual Studio 2005\Projects\SDL_FIRST_RUN My Game -Using Tiling Engine\SDL_FIRST_RUN\Debug\BuildLog.htm"
1>SDL_FIRST_RUN - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Main.cpp
1
2
3
4
5
6
7
8
9
10
//The headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
#include <fstream>

int main(int argc, char* args[])
{
	return 0;
}


StartUp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

//Screen attributes
//Original Values 640 x 480
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The frame rate
const int FRAMES_PER_SECOND = 32;

//The dot dimensions
const int DOT_WIDTH = 20;
const int DOT_HEIGHT = 20;

//The dimensions of the level Original Values 1280 x 960
const int LEVEL_WIDTH = 1360; //34 Tiles Across
const int LEVEL_HEIGHT = 1360; //34 Tiles Down

//Tile constants
const int TILE_WIDTH = 40;
const int TILE_HEIGHT = 40;
//Original value 192
const int TOTAL_TILES = 1156;
const int TILE_SPRITES = 12;

//The different tile sprites
const int TILE_RED = 0;
const int TILE_GREEN = 1;
const int TILE_BLUE = 2;
const int TILE_CENTER = 3;
const int TILE_TOP = 4;
const int TILE_TOPRIGHT = 5;
const int TILE_RIGHT = 6;
const int TILE_BOTTOMRIGHT = 7;
const int TILE_BOTTOM = 8;
const int TILE_BOTTOMLEFT = 9;
const int TILE_LEFT = 10;
const int TILE_TOPLEFT = 11;

//The surfaces
SDL_Surface *dot = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *tileSheet = NULL;

//Sprite from the tile sheet
SDL_Rect clips[TILE_SPRITES];

//The event structure 
SDL_Event event;

//The camera
SDL_Rect camera = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };

void StartUp()
{
		
}


StartUp.h
1
2
3
4
5
6
#ifndef STARTUP_H
#define STARTUP_H

void StartUp();

#endif //STARTUP_H 


Graphix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "graphix.h"

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
#include <fstream>

SDL_Surface *load_image(std::string filename) 
{
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized surface that will be used
    SDL_Surface* optimizedImage = NULL;
    
    //Load the image
    loadedImage = IMG_Load( filename.c_str() );
    
    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized surface
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        //Free the old surface
        SDL_FreeSurface( loadedImage );
        
        //If the surface was optimized
        if( optimizedImage != NULL )
        {
            //Color key surface
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
        }
    }
    
    //Return the optimized surface
    return optimizedImage;
}

void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination, SDL_Rect *clip = NULL)
{
    //Holds offsets
    SDL_Rect offset;
    
    //Get offsets
    offset.x = x;
    offset.y = y;
    
    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}


Graphix.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef GRAPHIX_H
#define GRAPHIX_H

#include "SDL/SDL.h"
#include <string>
#include <fstream>

SDL_Surface *load_image(std::string filename);
void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination, SDL_Rect *clip = NULL);

#endif //GRAPHIX_H 


As you can see my error is in the graphix.cpp and .h - I'm just not exactly sure what I'm doing wrong here. I've used sdl a while ago but just started again heh.
Nov 22, 2008 at 3:27am
Ok, i think it's fixed - In the Graphix.h file SDL_Rect *clip = NULL - i changed it to SDL_Rect *clip. Now I have no errors. Do you think that solves this problem fine or i'll get errors lol?
Nov 22, 2008 at 3:38am
The problem is that the default parameter has to be specified in only one place. Either in the declaration or the definition, but not both (I know, I was confused by this at first, too. Doesn't make much sense, does it?). I'm pretty sure, from the point of view of the compiler, it's the same, but I think it's better to put it in the header for documentation purposes (how would the user of the function know there are default parameters if there is no .cpp and no documentation?).
Last edited on Nov 22, 2008 at 3:39am
Nov 22, 2008 at 3:49am
Thanks a heap for that helios - that explains it a lot better. Cheers
Topic archived. No new replies allowed.