Hello there.
I've been trying to make my very first game . Right now I'm at the menubuilding stage.
I'm trying to have a button class that can be initialized with its caption, X and Y relative coordinates, width and height. However, when I try to create an instance and initialize its caption, I get a compiler error:
error: expected identifier before string constant
Here's the code that matters (I'll point out with a comment the line where the error occurs).
GUI.h
class Button
{
public:
Button(string c, int pX, int pY, int w, int h) : caption(c),
percX(pX),
percY(pY),
width(w),
height(h) {}
private:
int width;
int height;
// The percentage of X and Y displacement relative to total screen width/height.
// Counting from the left/up.
int percX;
int percY;
string caption;
};
game.h:
class Game
{
public:
// blablabla
private:
// more blablabla
// GUI elements
Button bSstart( "StartGame", 50, 20, 50, 5); // --> ERROR OCCURS HERE
Button bOptions( "GameOptions", 50, 25, 50, 5);
Button bHighScores( "HighScores", 50, 30, 50, 5);
Button bAbout( "About", 50, 35, 50, 5);
Button bExitAll( "ExitGame", 50, 40, 50, 5);
I can't figure out what's wrong... I'm passing a string literal to initialize a string (the button's caption). Why would I need an identifier?