mardi 27 janvier 2015

C++, Typedef a Static getInstance function

I Have this singleton "TextureHandler" Class which works fine using this "TextureHandler::getInstance()->functionName()", But... what i want to do is making a typedef "TxHandler" for the getInstance() function, so i can use it like this "TxHandler->functionName()", But I'm getting this error: expected initializer before 'TxHandler'.



#ifndef TEXTUREHANDLER_H
#define TEXTUREHANDLER_H

#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <iostream>
#include <string>
#include <map>
#include "Defs.h"

// Engine's texture handler class
class TextureHandler
{
// private constructor for singleton
TextureHandler() {}
static TextureHandler* instance;

// textures string map
map<string, SDL_Texture*> tMap;

public:
// getInstance singleton function
static inline TextureHandler* getInstance()
{
if(instance == NULL)
{
// create a pointer to the object
instance = new TextureHandler();
return instance;
}
return instance;
}

bool load(SDL_Renderer* renderer, string id, const char* filename);
bool loadText(SDL_Renderer* renderer, string id, const char* text, TTF_Font* font, SDL_Color color);
void render(SDL_Renderer* renderer, string id, int x, int y, int w=0, int h=0, int center=0, SDL_Rect* clip=NULL, SDL_RendererFlip flip=SDL_FLIP_NONE);
void free(string id);
int getWidth(string id);
int getHeight(string id);
};

// TextureHandler instance typedef
typedef TextureHandler::getInstance() TxHandler;

#endif

Aucun commentaire:

Enregistrer un commentaire