Advertisement

VS2k3 "constructors not allowed a return type", but no return is present

Started by March 18, 2006 01:02 AM
10 comments, last by GameDev.net 18 years, 9 months ago
When I compile this code I get this Error: d:\Visual Studio Projects\Tile\Tile.cpp(16): error C2533: 'Tile::__ctor' : constructors not allowed a return type what could be causing this error even though there is no return type listed? Tile.cpp

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

#include "Graphics.h"
#include "Logger.h"
#include "Tile.h"

Tile::Tile( Graphics graph, Uint8 tile_Size, std::string tilefile, std::string tileMapfile, std::string objectfile, std::string objectMapFile )
{
	this->m_Graphics	= graph;
	this->tileSize		= tile_Size;
	this->tileSheet		= this->m_Graphics->loadimage( TileFile );
	this->objectSheet	= this->m_Graphics->loadimage( objectFile );
	this->loadmap( tileMapFile );
	this->loadmap( objectMapFile );
}

Tile::~Tile( void )
{
	SDL_FreeSurface( this->tileSheet );
	SDL_FreeSurface( this->objectSheet );
}
Tile.h

#ifndef TILE_H
#define TILE_H

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

#include "Graphics.h"
#include "Logger.h"

class Tile
{
public:
	Tile::Tile( Graphics graph, Uint8 tile_Size, std::string tilefile, std::string tileMapfile, std::string objectfile, std::string objectMapFile );
	~Tile( void );
private:
	void loadmap( std::string filename );

	Graphics *m_Graphics;
	SDL_Surface *tileSheet;
	SDL_Surface *objectSheet;
	Uint8 tileSize;
	Uint8 tileMap[2][2][16][12];
	Uint8 objectMap[2][2][16][12];
}

#endif
[/source
-Matt S.
class Tile
{
public:
Tile::Tile( blah );

that's why.
Tile::Tile in the declaration. Should be just Tile.
Advertisement
Try removing the Tile::Tile from the header.
thnx for pointing that out. Unluckily that doesn't seem to be what's causing the problem.
-Matt S.
Would you mind also giving us a piece of the other includes there? Graph.h and Logger.h.

There is a chance that Logger.h, being included right before the class is declared, is not ended correctly.
Here:

Logger.h
#include <string>#include <iostream>#include <fstream>#ifndef LOGGER_H#define LOGGER_H#define LOGNAME "game.log"class Logger{private:	struct lg	{		// Member variables filled by the constructor		std::ofstream &out;		std::string module;		// Overload << to write to the ostream		void operator<< ( const std::string &val);		// Construct by timestamping this line		// (and filling in the member variables while we're here)		lg(std::ofstream &out, char *mod);		// Destruct by flushing out the line		~lg();		std::string stamp();	};public:	static lg log( char *modu )	{		static std::ofstream of( LOGNAME, std::ios::app);		return lg( of, modu);	}};#endif


Graphics.h
#ifndef ENGINE_H#define ENGINE_H#include <SDL.h>#include <SDL_image.h>#include <SDL_TTF.h>#include <string>class Graphics{public:	Graphics( Uint32 Width, Uint32 Height, std::string Title,				Uint8 bgR, Uint8 bgG, Uint8 bgB,				std::string font_Name, Uint8 font_Size);	~Graphics( void );	void ClearScreen();	SDL_Surface *loadimage( std::string filename );	void closeimage( SDL_Surface *Image );	void beginScene( void );	void endScene( void );	void drawText( std::string text, Uint32 x, Uint32 y,					Uint8 fR, Uint8 fG, Uint8 fB,					Uint8 bR, Uint8 bG, Uint8 bB);	SDL_Surface *drawSprite( SDL_Rect *src, SDL_Rect *dst, SDL_Surface *srcImage, SDL_Surface *dstImage );	void drawSprite( Uint32 srcx, Uint32 srcy, Uint32 dstx,					Uint32 dsty, Uint32 width, Uint32 height, SDL_Surface *srcImage );	void drawSprite( SDL_Rect *dst, SDL_Surface *srcImage );	TTF_Font *getFont( void );private:	void setBackgroundColor( Uint8 r, Uint8 g, Uint8 b);	// -- Holds the Backgroung Color of the screen for beginScene()	Uint8 backgroundColorRed;	Uint8 backgroundColorGreen;	Uint8 backgroundColorBlue;	// -- Holds the Basic data for the window for quick reference	Uint32 windowHeight;	Uint32 windowWidth;	std::string windowTitle;	SDL_Surface *screen;	// -- Holds the main window surface	TTF_Font *font;			// -- Holds the font for the game to use};#endif


Logger.cpp
#include "Logger.h"#include <fstream>#include <ctime>std::string Logger::lg::stamp(){	struct tm *ti;	time_t epochtime;	char str[32];	time(&epochtime);            // Get the number of seconds since 1970	ti = localtime(&epochtime);  // and convert to a date/time structure	sprintf(str,			"[%04d%02d%02d %02d:%02d:%02d]",			ti->tm_year + 1900,			ti->tm_mon + 1,			ti->tm_mday,			ti->tm_hour,			ti->tm_min,			ti->tm_sec);	return std::string(str);}Logger::lg::~lg(){	out.flush();}// -- Constructer, outputs timeLogger::lg::lg(std::ofstream &out, char *mod) : out(out){	module = mod;	out << std::endl << stamp() << ": " << module << ": ";}// Overload << to write to the ofstreamvoid Logger::lg::operator<< ( const std::string &val){	out << val;}


Graphics.cpp
#include <SDL.h>#include <SDL_TTF.h>#include <SDL_image.h>#include <string>#include <vector>#include "Graphics.h"#include "Logger.h"Graphics::Graphics( Uint32 Width, Uint32 Height, std::string Title,				Uint8 bgR, Uint8 bgG, Uint8 bgB,				std::string font_Name, Uint8 font_Size){	SDL_WM_SetCaption( Title.c_str(), NULL );		if( SDL_Init( SDL_INIT_EVERYTHING ) == -1)	{		Logger::log("Graphics" ) << "Failed to Initialize SDL";	}		if( ( screen = SDL_SetVideoMode( Width, Height, NULL, SDL_HWSURFACE | SDL_DOUBLEBUF ) ) == NULL )	{		Logger::log( "Graphics" ) << "Failed to Initialize screen";	}	this->setBackgroundColor( bgR, bgG, bgB );	if( TTF_Init() == -1 )		Logger::log( "Font" ) << "Failed to Initialize SDL_TTF";	this->font = TTF_OpenFont( font_Name.c_str(), font_Size);}Graphics::~Graphics( void ){	TTF_CloseFont(font);	TTF_Quit();	SDL_Quit();}void Graphics::beginScene(){   SDL_FillRect(screen,                NULL,                SDL_MapRGB(screen->format, backgroundColorRed,                                             backgroundColorGreen,                                             backgroundColorBlue));}void Graphics::endScene(){   SDL_Flip(screen);}SDL_Surface *Graphics::loadimage( std::string filename ){	SDL_Surface *loaded = NULL;	// -- Temp Space to hold image	SDL_Surface *final = NULL;	// -- The Final Surface that is returned	// -- Load the image	loaded = IMG_Load( filename.c_str() );	// -- Error checking to see if it loaded	if( loaded != NULL )	{		// -- Convert final and Copy Image		final = SDL_DisplayFormat( loaded );		// -- Free memory		SDL_FreeSurface( loaded );	}	else if (loaded == NULL)	{		Logger::log("Graphics") << "Failed to image: ";		Logger::log("Graphics") << filename.c_str();	}		// -- return image	return final;}void Graphics::closeimage( SDL_Surface *Image ){	SDL_FreeSurface( Image );}SDL_Surface *Graphics::drawSprite( SDL_Rect *src, SDL_Rect *dst, SDL_Surface *srcImage, SDL_Surface *dstImage ){	SDL_BlitSurface( srcImage, src, dstImage, dst );	delete src;	delete dst;	return dstImage;}void Graphics::drawSprite( SDL_Rect *dst, SDL_Surface *srcImage ){	SDL_BlitSurface( srcImage, NULL, this->screen, dst );	delete dst;}void Graphics::drawSprite( Uint32 srcx, Uint32 srcy, Uint32 dstx,					Uint32 dsty, Uint32 width, Uint32 height, SDL_Surface *srcImage ){	// -- Holds source and destination locations for image transfer	SDL_Rect src;	SDL_Rect dst;	dst.h = src.h = height;	dst.w = src.w = width;	src.x = srcx;	src.y = srcy;	dst.x = dstx;	dst.y = dsty;	SDL_BlitSurface( srcImage, &src, screen, &dst );}void Graphics::setBackgroundColor( Uint8 r, Uint8 g, Uint8 b){	this->backgroundColorBlue = b;	this->backgroundColorGreen = g;	this->backgroundColorRed = r;}void Graphics::drawText(std::string text, Uint32 x, Uint32 y,					Uint8 fR, Uint8 fG, Uint8 fB,					Uint8 bR, Uint8 bG, Uint8 bB){	SDL_Color foregroundColor = { fR, fG, fB };	SDL_Color backgroundColor = { bR, bG, bB };	SDL_Surface* textSurface = TTF_RenderText_Shaded(font, text.c_str(),													foregroundColor, backgroundColor);	SDL_Rect textLocation = { x, y, 0, 0 };	SDL_BlitSurface(textSurface, NULL, screen, &textLocation);	SDL_FreeSurface(textSurface);}TTF_Font *Graphics::getFont( void ){	return font;}
-Matt S.
Advertisement
There you go everything what they said.
A few hints...

//Somewhere in declaration space
using std::string;

//local or global example
string something;


of if your lazy and want a real slow piece of junk
//Somewhere in declaration space
using namespace std;


class Tile{public:	Tile( Graphics graph, Uint8 tile_Size, std::string tilefile, std::string tileMapfile, std::string objectfile, std::string objectMapFile );	~Tile( void );private:	void loadmap( std::string filename );	Graphics *m_Graphics;	SDL_Surface *tileSheet;	SDL_Surface *objectSheet;	Uint8 tileSize;	Uint8 tileMap[2][2][16][12];	Uint8 objectMap[2][2][16][12];};


I hope this helps also... And if you already knew about that and you enjoy doing the long std:: stuff then disregard my std:: crap.
Nice catch. Didn't even see that one.
thanks, I've spent forever trying to figure out whats wrong with it.
-Matt S.
Quote: Original post by Riekistyx
of if your lazy and want a real slow piece of junk
//Somewhere in declaration space
using namespace std;


'Using' a namespace does not incur *any* overhead. All it does is instruct the compiler about name lookup, i.e. how to interpret symbols that it couldn't otherwise identify. The only thing that *might* be (negligibly) slower is the compilation process.

This topic is closed to new replies.

Advertisement