I'm writing wrapper for displaying text and I have a problem that I cant solve.
Class header:
class CRender
{
public:
static sf::Font openSans; //this is my problem, I'll explain it below this code
void write(string & text, sf::RenderWindow & window, short int x, short int y, short int size = 30, sf::Font & font = openSans);
};
So i want to load font from file into the openSans object once, and then use it as default font in my function. Complilator said me that if I want to have default value in my "write" function it must be static member. Okay, no problem.
So there is my class' cpp file:
sf::Font CRender::openSans.loadFromFile("data/fonts/SourceSansPro-Regular.ttf"); //and this is forbidden
void CRender::write(string & text, sf::RenderWindow & window, short int x, short int y, short int size, sf::Font & font)
{
sf::Text temp(text, font, size);
temp.setPosition(x, y);
window.draw(temp);
}
In first line of this cpp file i get error C2143: syntax error : missing ';' before '.'.
I have no idea what to do to have that font object with preloaded font ready to use in my function. Any ideas how to do it?
The reason may be that sf::Font doesn't have load from file constructor, maybe if I rewrite its constructor it will solve the problem? Coz I think that using constructor to initialize static member is allowed.
edit:
I'm using sfml 2.0 ofc, compiler is VC++ 2008 so maybe C++ 11 would allow to do it without problems, if you just know something please reply.
Thanks