Stupid header problem

Started by
15 comments, last by erissian 16 years, 5 months ago
I'm getting a compiler error when I compile my simple SDL App. I'm sure it's something small. Thanks James

/*
 *  SDL_Video.h
 *  Created by James Hammond on 11/3/07
 */

#ifndef SDL_VIDEO_H
#define	SDL_VIDEO_H

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

#endif


/*
 *  SDL_Video.cpp
 *  Created by James Hammond on 11/3/07
 */
#include <string>
#include "SDL.h"
#include "SDL_image.h"

using namespace std;

SDL_Surface *load_image( std::string filename ) 
{
    //Temporary storage for the image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;
	
	//Load the image
    loadedImage = IMG_Load( filename.c_str() );
	
	//If nothing went wrong in loading the image
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        //Free the old image
        SDL_FreeSurface( loadedImage );
    }
	
	//Return the optimized image
    return optimizedImage;
}


void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;
	
	   //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &offset );
}

James HammondUniversity of ColoradoDepartment of Computer Science
Advertisement
A compiler error? Would you mind posting it?
Check out my devlog.
Sorry, forgot to point out the most important part of the post!

syntax error before ':' token

Te error is pointing towards the header.

Thanks
James!
James HammondUniversity of ColoradoDepartment of Computer Science
#include <string>

You need it in the header, the compiler doesn't know std::string.
And you do also probably need #include <SDL.h> in the header too, as you're using the SDL_Surface there.
Check out my devlog.
Better to just forward declare it, since it's only passing pointers around.
class SDL_Surface;
Also you probably want to include your header file in the source file. And naming your header SDL_video.h is not a good idea since there already exists a header file with this name among the SDL include files.
After making some of the changes suggested, I now have two errors:

error: string: No such file or directory
error: syntax error before ':' token

Weird thing about the string error is that I'm using it in the definition file without any problems.

Here is my updated header file:

#ifndef SDL_VIDEO_H#define	SDL_VIDEO_H#include "SDL.h"#include <string>SDL_Surface* load_image(std::string filename);void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination );#endif
James HammondUniversity of ColoradoDepartment of Computer Science
How are you compiling it? That looks like it believes it's C code.
In Xcode 3.0, OS X. Does anyone know how to update the build setting to allow both c and c++ code in the same project?

Thanks
James
James HammondUniversity of ColoradoDepartment of Computer Science

This topic is closed to new replies.

Advertisement