I've declared a global enum type in my program and want various functions within my program to return instances of the enum type. Here is my declaration:
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <SDL.h>
#include "LTexture.h"
#include "LButton.h"
#include "Initializationetc.h"
enum LButtonSprite
{
BUTTON_SPRITE_MOUSE_OUT = 0,
BUTTON_SPRITE_MOUSE_OVER_MOTION = 1,
BUTTON_SPRITE_MOUSE_DOWN = 2,
BUTTON_SPRITE_TOTAL = 2
};
...
However, when I go try and build a function that returns "LButtonSprite" the following happens:
#ifndef LBUTTON_H
#define LBUTTON_H
#include <SDL.h>
#include "Global.h"
class LButton
{
public:
//Initializes internal variables
LButton();
//Sets top left position
void setPosition(int x, int y);
//Handles mouse event
void handleEvent(SDL_Event* e);
//Shows button sprite
void render();
LButtonSprite getCurrSprite();//here
private:
//Button Position
SDL_Point mPosition;
//Button Sprite
LButtonSprite mCurrentSprite; //and here.
};
#endif
It seems as if the Visual Studio is mistaking the function prototype LButtonSprite getCurrSprite();
for a declaration of a variable called getCurrSprite() of type LButtonSprite. The colour coding provided by VS (as seen above) seems to confirm this suspicion. Return types are blue, but LButtonSprite is light blue which is the colour reserved for variables.
The problem isn't just cosmetic unfortunately. I'm getting a bunch ofC4430: missing type specifier - int assumed. Note: C++ does not support default-int. I've added comments to the code at the lines where the error is occurring. The complete error log is included at the end of the post.
How can I correct this mistake?
Error log:
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials Error 14 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\global.h 34 1 SDL2_tutorials Error 17 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials Error 20 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials Error 4 error C2146: syntax error : missing ';' before identifier 'mCurrentSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials Error 10 error C2146: syntax error : missing ';' before identifier 'mCurrentSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials Error 19 error C2146: syntax error : missing ';' before identifier 'mCurrentSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 29 1 SDL2_tutorials Error 1 error C2146: syntax error : missing ';' before identifier 'getCurrSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials Error 7 error C2146: syntax error : missing ';' before identifier 'getCurrSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials Error 16 error C2146: syntax error : missing ';' before identifier 'getCurrSprite' c:\users\adam\documents\visual studio 2013\projects\sdl2_tutorials\sdl2_tutorials\lbutton.h 22 1 SDL2_tutorials
Return types are blue
No – keywords are blue. Why else would enum
, class
, public
and private
be blue? Return types have no special syntax highlighting. The problem in your code is completely unrelated:
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <SDL.h>
#include "LTexture.h"
#include "LButton.h"
The last line includes (and thus declares) the LButton
class, before you define your enum
. Remove that line from the file, or define the enum before.