Sign in to follow this  

Stupid header problem

This topic is 3727 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
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
And you do also probably need #include <SDL.h> in the header too, as you're using the SDL_Surface there.

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
Quote:
Original post by Hammonjj

//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() );



first question for any one this is for me.
1) since this is a pointer doesnt loadedImage need a dereference before it (*loadedImage) and if not why not. I assume this is C++

2) since Im new to these forum is there a place to get the code for: edit, quote, paste code in a box etc... thanks in advance.

Please do talk technical.

My back ground is engineering: basic c++, basic java, data abstraction, problem solving microcomputers, computer microprocessors, electronics. I can tell how the computer works to detail just not how to code it in higer level language. Hense the reason I watch these forums help me understand some of the details.

Share this post


Link to post
Share on other sites
Quote:

1) since this is a pointer doesnt loadedImage need a dereference before it (*loadedImage) and if not why not. I assume this is C++


IMG_Load probably returns a pointer. If you had int* p, then p is a pointer and *p is an integer.

Quote:

2) since Im new to these forum is there a place to get the code for: edit, quote, paste code in a box etc... thanks in advance.


The FAQ tells all.

Share this post


Link to post
Share on other sites
Quote:
Original post by FritoBandito
Ironhand69,

The syntax is fine because this is a pointer assignment (IMG_Load returns SDL_Surface*).

Hope that helps.


yes that helps a lot thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by erissian
A C++ compiler shouldn't complain about C code.

On the contrary, my thought was that he might be feeding C++ code to a C only compiler.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gaenor
Quote:
Original post by erissian
A C++ compiler shouldn't complain about C code.

On the contrary, my thought was that he might be feeding C++ code to a C only compiler.


I should make it a point to quote more often. I was responding to this:

Quote:
Original post by Hammonjj
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