Jump to content
  • Advertisement
Sign in to follow this  
Hammonjj

Stupid header problem

This topic is 4054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 );
}

Share this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!