CodeBlocks Ожидаемое имя класса до {token - но нет синтаксической проблемы - PullRequest
2 голосов
/ 08 мая 2019

Я работаю над кодом в блоках кода, и следующие вопросы относятся к этому вопросу:

#ifndef MAPOBJECT_H
#define MAPOBJECT_H

#include "global.h"
#include "ModeTypes.h"

class MapObject
{
    public:
        /** Default constructor */
        MapObject();
        MapObject(bool c, bool o, SDL_Rect loc);
        /** Default destructor */
        virtual ~MapObject();

        ...
};

#endif // MAPOBJECT_H

Это класс, который мои игровые объекты унаследуют от

#ifndef INVENTORYITEM_H
#define INVENTORYITEM_H

//#include "ModeTypes.h"
#include "MapObject.h"
//#include <MapObject.h>

class InventoryItem : public MapObject
{ //<----------this is where the error happens
    //!inventoryitem size is assumed: 16x16 px.
    public:
        /** Default constructor */
        InventoryItem();
        //InventoryItem(bool c, bool o, SDL_Rect loc);//not needed?
        InventoryItem(itemStatSheet itemStats);
        /** Default destructor */
        virtual ~InventoryItem();

        bool collision (MapObject& source);
        bool interact (MapObject& source);
        bool use(MapObject& source);
        bool drop(MapObject& source, SDL_Point destination);

        ...

};

#endif // INVENTORYITEM_H

И это мой родительский класс элементов, который наследуется от MapObject.

Проблема иногда в том, что, хотя я не изменил ни свой класс InventoryItem, ни мой класс MapObject, я получу эту ошибку компиляции:

Ожидаемое имя класса до {token

Теперь я знаю, какие потенциальные причины этой ошибки могут быть в нормальной среде, но вот сумасшедшая вещь: путьЯ обнаружил, что могу многократно исправить ошибку ...

1 Сохраните мою работу

2 Закомментируйте все строки, которые используют MapObject в InventoryItem, поэтому код выглядит следующим образом:

#ifndef INVENTORYITEM_H
#define INVENTORYITEM_H

//#include "ModeTypes.h"
#include "MapObject.h"
//#include <MapObject.h>

class InventoryItem //: public MapObject
{
    //!inventoryitem size is assumed: 16x16 px.
    public:
        /** Default constructor */
        InventoryItem();
        //InventoryItem(bool c, bool o, SDL_Rect loc);//not needed?
        InventoryItem(itemStatSheet itemStats);
        /** Default destructor */
        virtual ~InventoryItem();

        //bool collision (MapObject& source);
        //bool interact (MapObject& source);
        //bool use(MapObject& source);
        //bool drop(MapObject& source, SDL_Point destination);

3 Компиляция (успех)

4 Раскомментируйте эти строки, чтобы они вернулись, как это было

5 Компиляция (успех)

У меня нетне смог понять, что вызываетпроблема, но это случилось несколько раз, и это сводит меня с ума.Есть какие-нибудь намеки на то, что может происходить?

Вот мои настройки компоновщика:

-lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_net -lsqlite3 -static-libgcc -static-libstdc ++ -Wl, -Bstatic -lstdc ++ -lpthread -Wl, -Bdynamic

Я работаю в Windows 10 с mingw-w64.

Журнал сборки по запросу:

-------------- Build: Debug in Heir (compiler: MinGW-W64)---------------

x86_64-w64-mingw32-g++.exe -Wall -fexceptions -g -Weffc++ -Iinclude -IC:\SDL2-2.0.8\x86_64-w64-mingw32\include\SDL2 -IC:\sqlite\include -I"C:\Users\user\Documents\CPP Projects\Heir\src" -I"C:\Users\user\Documents\CPP Projects\Heir" -c "C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp" -o obj\Debug\src\MapBuilderMode.o
x86_64-w64-mingw32-g++.exe -LC:\SDL2-2.0.8\x86_64-w64-mingw32\lib -LC:\sqlite\lib -o bin\Debug\Heir.exe obj\Debug\main.o obj\Debug\src\Character.o obj\Debug\src\ControlScheme.o obj\Debug\src\GameMode.o obj\Debug\src\global.o obj\Debug\src\InventoryItem.o obj\Debug\src\LButton.o obj\Debug\src\LScrollBar.o obj\Debug\src\LTextInput.o obj\Debug\src\LTextOutput.o obj\Debug\src\LTexture.o obj\Debug\src\LTimer.o obj\Debug\src\LWindow.o obj\Debug\src\MainMenuMode.o obj\Debug\src\MapBuilderMode.o obj\Debug\src\MapConstruct.o obj\Debug\src\MapObject.o obj\Debug\src\ModeTypes.o obj\Debug\src\NameGenerator.o obj\Debug\src\PController.o obj\Debug\src\sqlite3.o  -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_net -lsqlite3 -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic  
In file included from include/MapBuilderMode.h:4:0,
                 from C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:1:
include/global.h:43:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string PERSON_SPRITEFILE_BODY = "Media/PSPH Body.png";
                                 ^~~~~~~~~~~~~~~~~~~~~~
include/global.h:44:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string PERSON_SPRITEFILE_HAT = "Media/PSPH Hat.png";
                                 ^~~~~~~~~~~~~~~~~~~~~
include/global.h:45:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string PERSON_SPRITEFILE_SHOE = "Media/PSPH Shoe.png";
                                 ^~~~~~~~~~~~~~~~~~~~~~
include/global.h:46:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string SCROLLBAR_SPRITEFILE = "Media/ScrollbarSprites_Combined.png";
                                 ^~~~~~~~~~~~~~~~~~~~
include/global.h:47:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string BUTTON_SPRITEFILE = "Media/ButtonSprites.png";
                                 ^~~~~~~~~~~~~~~~~
include/global.h:48:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string ITEM_BASIC_SPRITEFILE = "Media/Items/basic.png";
                                 ^~~~~~~~~~~~~~~~~~~~~
include/global.h:49:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string CONSTRUCT_BASIC_SPRITEFILE = "Media/Constructs/basic.png";
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/global.h:94:33: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const std::string FONT_NAME = "Gotham-Book.ttf";
                                 ^~~~~~~~~
include/global.h:107:66: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const SDL_MessageBoxButtonData confirmationButtons[] = {
                                                                  ^
include/global.h:112:47: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const SDL_MessageBoxColorScheme confirmationColorScheme = {
                                               ^~~~~~~~~~~~~~~~~~~~~~~
include/global.h:126:40: warning: inline variables are only available with -std=c++1z or -std=gnu++1z
 extern inline const SDL_MessageBoxData confirmationBoxdata = {
                                        ^~~~~~~~~~~~~~~~~~~
In file included from include/Character.h:5:0,
                 from include/ModeTypes.h:4,
                 from include/MapBuilderMode.h:5,
                 from C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:1:
include/LTexture.h:10:7: warning: 'class LTexture' has pointer data members [-Weffc++]
 class LTexture
       ^~~~~~~~
include/LTexture.h:10:7: warning:   but does not override 'LTexture(const LTexture&)' [-Weffc++]
include/LTexture.h:10:7: warning:   or 'operator=(const LTexture&)' [-Weffc++]
include/LTexture.h:42:72: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
   void render( int x, int y, SDL_Rect* clip = NULL, int targetHeight = NULL, int targetWidth = NULL, double angle = 0.0, SDL_Point* center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE );
                                                                        ^~~~
include/LTexture.h:42:96: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
   void render( int x, int y, SDL_Rect* clip = NULL, int targetHeight = NULL, int targetWidth = NULL, double angle = 0.0, SDL_Point* center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE );
                                                                                                ^~~~
In file included from include/ModeTypes.h:4:0,
                 from include/MapBuilderMode.h:5,
                 from C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:1:
include/Character.h:14:7: warning: 'class Character' has pointer data members [-Weffc++]
 class Character
       ^~~~~~~~~
include/Character.h:14:7: warning:   but does not override 'Character(const Character&)' [-Weffc++]
include/Character.h:14:7: warning:   or 'operator=(const Character&)' [-Weffc++]
In file included from include/ModeTypes.h:8:0,
                 from include/MapBuilderMode.h:5,
                 from C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:1:
include/LScrollBar.h: In constructor 'LScrollBar::LScrollBar(LTexture&, SDL_Rect (&)[5], SDL_Rect (&)[5], SDL_Rect (&)[5], SDL_Rect (&)[5])':
include/LScrollBar.h:16:3: warning: 'LScrollBar::mPosition' should be initialized in the member initialization list [-Weffc++]
   LScrollBar(LTexture& spriteSheet,SDL_Rect (&upClips)[5], SDL_Rect (&downClips)[5], SDL_Rect (&gripperClips)[5], SDL_Rect (&pageClips)[5]):
   ^~~~~~~~~~
include/LScrollBar.h:16:3: warning: 'LScrollBar::mScrollbarHeight' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mScrollButtonSize' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mListItemPitch' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mTotalListItems' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mScrollPercent' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mScrollTravelDistance' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mUpButton' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mDownButton' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mGripperButton' should be initialized in the member initialization list [-Weffc++]
include/LScrollBar.h:16:3: warning: 'LScrollBar::mPageButton' should be initialized in the member initialization list [-Weffc++]
In file included from include/InventoryItem.h:5:0,
                 from include/ModeTypes.h:11,
                 from include/MapBuilderMode.h:5,
                 from C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:1:
include/MapObject.h: In member function 'SDL_Rect MapObject::setRect(SDL_Rect)':
include/MapObject.h:19:50: warning: no return statement in function returning non-void [-Wreturn-type]
   SDL_Rect setRect(SDL_Rect loc){mLocation = loc;}
                                                  ^
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In constructor 'MapBuilderMode::MapBuilderMode()':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mCurrentZone' should be initialized in the member initialization list [-Weffc++]
 MapBuilderMode::MapBuilderMode()
 ^~~~~~~~~~~~~~
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mCurrentLayer' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mCurrentTool' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mCurrentTileset' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mLastZone' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mLastLayer' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mLastTool' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mLastTileset' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mTitleBarHeight' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mPanelOutlineWidth' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mToolColumnWidth' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mTotalLayers' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mTotalTilesets' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mLayout' should be initialized in the member initialization list [-Weffc++]
In file included from include/MapBuilderMode.h:5:0,
                 from C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:1:
include/ModeTypes.h: In constructor 'modeLayout::modeLayout()':
include/ModeTypes.h:33:3: warning: 'modeLayout::panelOutlines' should be initialized in the member initialization list [-Weffc++]
 } modeLayout;
   ^~~~~~~~~~
include/ModeTypes.h:33:3: warning: 'modeLayout::panelInternals' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In constructor 'MapBuilderMode::MapBuilderMode()':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:32: note: synthesized method 'modeLayout::modeLayout()' first required here 
 MapBuilderMode::MapBuilderMode()
                                ^
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mButtons' should be initialized in the member initialization list [-Weffc++]
 MapBuilderMode::MapBuilderMode()
 ^~~~~~~~~~~~~~
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mButtonStringTextures' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mScrollbars' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mCheckBoxes' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mRadioButtons' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mTextDisplays' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mTextInputs' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mColorOverlays' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:3:1: warning: 'MapBuilderMode::mMapZones' should be initialized in the member initialization list [-Weffc++]
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:21:15: warning: statement has no effect [-Wunused-value]
  CHECKBOX_SIZE; //16
               ^
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:22:17: warning: statement has no effect [-Wunused-value]
  SCROLL_BAR_SIZE; //20
                 ^
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In member function 'void MapBuilderMode::handleEvent(SDL_Event&)':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:40:3: warning: statement has no effect [-Wunused-value]
  1;
   ^
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In member function 'void MapBuilderMode::proceed()':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:44:3: warning: statement has no effect [-Wunused-value]
  1;
   ^
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In member function 'void MapBuilderMode::setGraphics()':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:104:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < mLayout.panelInternals.size(); i++)
                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In member function 'void MapBuilderMode::renderGraphics()':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:121:3: warning: statement has no effect [-Wunused-value]
  1;
   ^
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In member function 'void MapBuilderMode::initializeLayout()':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:297:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < mLayout.panelInternals.size(); i++)
                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp: In member function 'int MapBuilderMode::generateLayerList()':
C:\Users\user\Documents\CPP Projects\Heir\src\MapBuilderMode.cpp:310:19: warning: statement has no effect [-Wunused-value]
  gSelectedLoadMap.path;
  ~~~~~~~~~~~~~~~~~^~~~
Output file is bin\Debug\Heir.exe with size 7.42 MB
Process terminated with status 0 (0 minute(s), 3 second(s))
0 error(s), 64 warning(s) (0 minute(s), 3 second(s))

Журнал сборки с ошибками был слишком длинным для переполнения стека.Я вставил его содержимое в этот документ Google: https://docs.google.com/document/d/1Sz-MDwlMW7TsVszM_YmuV0PHfvcX9LkSSF5gC5UahKs/edit?usp=sharing

...