• Advertisement
Sign in to follow this  

Silly syntax errors

This topic is 3742 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

Hi everybody. This is a new account but I've used Gamdedev before, it's great :D Anyway, my problem is a small one. I recently switched from Dev-C++ to Code::Blocks and like it so far. Just to get started and mess around with some code, I installed SDL and attempted to make a small class that initializes a specified subsystem and creates a window (among other things). My programming skills are a little rusty because I haven't coded in a while, so some typical syntax errors popped when I compiled. After fixing these though, I still keep getting errors I don't see in my code. Most of them say something like "syntax error before CSDLMain" but the one that one doesn't scare me nearly as much as the one that says "string: no such file or directory". :/ I don't know if something is up with my compiler or if I'm just making stupid mistakes. I went through my C++ Primer and everything seems okay so I don't understand. Here's the header:
/* CSDLMain Header File
 * CSDLMain controls setting up and shutting down SDL, window creation and functions that have
   no place in the subsystems */

#ifndef CSDLMAIN_H
#define CSDLMAIN_H

#include <string>	// return value of 'Get_Error()'
using std::string;

#include <SDL/SDL.h>	// must include SDL for use of Uint32

class CSDLMain
{
    public:
           CSDLMain(Uint32 init_flags, int w, int h, int bpp, Uint32 format_flags);	// constructor

          ~CSDLMain();	// destructor

           void Init_System(Uint32 init_flags);	// initialize subsystem(s)
           void Init_Subsystem(Uint32 init_flags);	// initialize subsystem afterword

           void Quit_System();	// shuts down entire system
           void Quit_Subsystem(Uint32 init_flags);	// shuts down subsystem

           Uint32 Was_Init(Uint32 init_flags);	// returns system if initialized

           string Get_Error();	// returns error, write to log
           void Clear_Error();	// clears error, use after written error to log

           void Create_Window(int w, int h, int bpp, Uint32 format_flags);	// window creation
};

#endif

Here's the source:
/* CSDLMain Source File */

#include "csdlmain.h"

CSDLMain::CSDLMain(Uint32 init_flags, int w, int h, int bpp, Uint32 format_flags)
{
	Init_System(init_flags);

	Create_Window(w, h, bpp, format_flags);
}

CSDLMain::~CSDLMain()
{
	Quit_System();
}

void CSDLMain::Init_System(Uint32 init_flags)
{
	if(SDL_Init(init_flags) != 0)
	   fprintf(stderr, "Error, unable to initialize SDL.\n");
)

void CSDLMain::Init_Subsystem(Uint32 init_flags)
{
	if(SDL_InitSubSystem(init_flags) != 0)
	   fprintf(stderr, "Error, unable to initialize SDL.\n");
}

void CSDLMain::Quit_System()
{
	SDL_Quit();
}

void CSDLMain::Quit_Subsystem(Uint32 init_flags)
{
	SDL_QuitSubSystem(init_flags);
}

Uint32 CSDLMain::Was_Init(Uint32 init_flags)
{
	Uint32 subsystems = SDL_WasInit(init_flags);
	return subsystems;
}

string CSDLMain::Get_Error()
{
	string error(SDL_GetError());
	return error;
}

void CSDLMain::Clear_Error()
{
	SDL_ClearError();
}

void CSDLMain::Create_Window(int w, int h, int bpp, Uint32 format_flags)
{
	SDL_Surface *p_screen = SDL_SetVideoMode(w, h, bpp, format_flags);

	if(p_screen == 0)
	   fprintf(stderr, "Error, unable to create window.\n");
}

EDIT: Shoot, I'm sorry I've forgotten how to insert my code into a window so it doesn't take up the whole page, could someone tell me how to do that? Sorry :( [Edited by - Cpt Smoge on October 25, 2007 7:28:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Cpt Smoge
EDIT: Shoot, I'm sorry I've forgotten how to insert my code into a window so it doesn't take up the whole page, could someone tell me how to do that? Sorry :(


Put it between [ source ][ /source ] tags (without the spaces).

Share this post


Link to post
Share on other sites
Firstly, can you compile a simple hello world program in Code::Blocks? Try one without <string>, then one with it. It's surprisingly easy to get that compiler configured in such a way that you can't build anything with it.

Once you've confirmed that all works, could you please post the line numbers that these errors are on?

Share this post


Link to post
Share on other sites
Yes the string library works fine in main.cpp just not in my header file. It seems I can include anything in main.cpp but the .h files claim they do not exist. Here are the errors (in the comments):

#ifndef CSDLMAIN_H
#define CSDLMAIN_H

#include <string> // string: no such file or directory
using std::string; // syntax error befor std

#include <SDL/SDL.h>

class CSDLMain // syntax error before CSDLMain
{
public:
CSDLMain(Uint32 init_flags, int w, int h, int bpp, Uint32 format_flags);

~CSDLMain();

void Init_System(Uint32 init_flags);
void Init_Subsystem(Uint32 init_flags);

void Quit_System();
void Quit_Subsystem(Uint32 init_flags);

Uint32 Was_Init(Uint32 init_flags);

string Get_Error();
void Clear_Error();

void Create_Window(int w, int h, int bpp, Uint32 format_flags);
};

#endif

Share this post


Link to post
Share on other sites
Sounds to me like you're accidentally compiling with a C compiler instead of a C++ compiler. All the errors lead to this.

Share this post


Link to post
Share on other sites
Sounds like you got the compiler setup to parse .h files as ANSI-C or it parses them as Java or C# or something even stranger =D

Share this post


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

  • Advertisement