SDL Compile Error WTF

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

SDL Compile Error WTF

Post 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
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL Compile Error WTF

Post 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.
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

Re: SDL Compile Error WTF

Post by ajtgarber »

*facepalm* that was it, thanks! :)
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL Compile Error WTF

Post by X Abstract X »

haha, we've all done this sort of thing.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: SDL Compile Error WTF

Post 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.
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: SDL Compile Error WTF

Post by X Abstract X »

It's also a good idea to use the constructor's initializer list.

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