Page 1 of 1

SDL Compile Error WTF

Posted: Wed May 19, 2010 7:42 pm
by ajtgarber
System.h

Code: Select all

#pragma once

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

class System {
public:
	SDL_Surface *screen;
	System();
	
	bool init(string title, int width, int height, bool full);
};
System.cpp

Code: Select all

#include "System.h"
#include <string>

System::System() {
	screen = NULL;
}

bool System::init(string title, int width, int height, bool full) {
	if(SDL_Init(SDL_INIT_EVERYTHING) == -1) {
		return false;
	}
	
	if(full) {
		screen = SDL_SetVideoMode(width, height, 32, SDL_FULLSCREEN);
	} else {
		screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE);
	}
	if(screen == NULL) {
		return false;
	}
	
	SDL_WM_SetCaption(title.c_str(), NULL);
	
	return true;
}
Errors:

Code: Select all

	/Users/jacobgarber/Desktop/SDL/System.h:11: error: 'string' has not been declared
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: 'bool System::init' is not a static member of 'class System'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: 'string' was not declared in this scope
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'int'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'int'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'bool'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: initializer expression list treated as compound expression
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected ',' or ';' before '{' token
    cd /Users/jacobgarber/Desktop/SDL
    /Developer/usr/bin/gcc-4.0 -x c++ -arch ppc -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mfix-and-continue -mtune=G5 -fvisibility-inlines-hidden -mmacosx-version-min=10.4 -gdwarf-2 -I/Users/jacobgarber/Desktop/SDL/build/SDL.build/Debug/SDL.build/SDL.hmap -F/Users/jacobgarber/Desktop/SDL/build/Debug -F/Users/jacobgarber/Library/Frameworks -F/Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks -I/Users/jacobgarber/Desktop/SDL/build/Debug/include -I/Users/jacobgarber/Library/Frameworks/SDL.framework/Headers -I/Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/SDL.framework/Headers -I/Users/jacobgarber/Desktop/SDL/build/SDL.build/Debug/SDL.build/DerivedSources/ppc -I/Users/jacobgarber/Desktop/SDL/build/SDL.build/Debug/SDL.build/DerivedSources -include /var/folders/RI/RIxlp3ksGAWi66A-rj783E+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/SDL_Prefix-cgyewiqdyuzibvgjrihvkhvfkuez/SDL_Prefix.pch -c /Users/jacobgarber/Desktop/SDL/System.cpp -o /Users/jacobgarber/Desktop/SDL/build/SDL.build/Debug/SDL.build/Objects-normal/ppc/System.o
/Users/jacobgarber/Desktop/SDL/System.h:11: error: 'string' has not been declared
/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: 'bool System::init' is not a static member of 'class System'
/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: 'string' was not declared in this scope
/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'int'
/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'int'
/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'bool'
/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: initializer expression list treated as compound expression
/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected ',' or ';' before '{' token
	/Users/jacobgarber/Desktop/SDL/System.h:11: error: 'string' has not been declared
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: 'bool System::init' is not a static member of 'class System'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: 'string' was not declared in this scope
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'int'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'int'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected primary-expression before 'bool'
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: initializer expression list treated as compound expression
	/Users/jacobgarber/Desktop/SDL/System.cpp:8: error: expected ',' or ';' before '{' token
I have no idea what the hell is wrong with this thing, any help would be appreciated

Re: SDL Compile Error WTF

Posted: Wed May 19, 2010 7:52 pm
by X Abstract X
First issue that jumps right out is that string is part of the std namespace and you aren't treating it as such.

Re: SDL Compile Error WTF

Posted: Wed May 19, 2010 7:54 pm
by ajtgarber
*facepalm* that was it, thanks! :)

Re: SDL Compile Error WTF

Posted: Wed May 19, 2010 7:54 pm
by X Abstract X
haha, we've all done this sort of thing.

Re: SDL Compile Error WTF

Posted: Wed May 19, 2010 8:14 pm
by Bakkon
#include <string> is in your header, so you don't need to include it again in the cpp. Also, I'd go with #ifndef over #pragma.

Re: SDL Compile Error WTF

Posted: Wed May 19, 2010 9:55 pm
by X Abstract X
It's also a good idea to use the constructor's initializer list.

System::System() : screen(NULL) {}