3

new to this forum and to programming so please forgive any potential mistakes in my question. I am trying to code a game in c++ using SDL2 and Xcode 6.3.2. In my Game class (see below) Xcode does not recognise my destructor and gives me the error: expected member name or ';' after declaration I have no idea what is wrong with my destructor or my code in general. My question is simply: What have I done wrong? Thanks in advance!

update: Narrowed the issue down and ran the code in cpp.sh without any issues. Xcode still gives the error message and I am unable to build because of it. I have tried restarting my computer, deleting the derived data and cleaning the build folder but to no effect.

int main() {

class Game {

public:
    Game();
    ~Game(); //here is the issue
};

}

update 2: Simply removed the non working code and retyped it. The error message did not reappear and the build succeeded. Xcode had probably indeed cached the error message in some strange way.

osk
  • 31
  • 3
  • 1
    Are you sure it's not because xcode has cached the error messages? the code looks ok to me. – Olivier Sohn Jul 11 '18 at 18:04
  • This doesn’t address the question, but names that contain two consecutive underscores (`__Game1__Game__`) and names that begin with an underscore followed by a capital letter are reserved for use by the implementation. Don’t use them in your code. – Pete Becker Jul 11 '18 at 18:04
  • I see nothing wrong other than the header guard using an illegal identifier ([What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)) and that shouldn't cause the sort of problem you're seeing. Could we have a [mcve] please? – user4581301 Jul 11 '18 at 18:06
  • 1
    Welcome to Stack Overflow, by the way. Thank you for reading the tour on your way through. Question is a pretty good first post. All that is missing is a complete example that duplicates the issue, something which may take a bit of work to sort out. What you should do is back up your code and start removing pieces until the problem goes away to narrow the focus down until all you have is the minimum code required to trigger the error. If that doesn't have you groaning at the mistake and fixing it yourself, update your question with this minimal example. – user4581301 Jul 11 '18 at 18:14
  • 1
    Note that the error might not be in this file, but instead in a file that includes this file or another header included by the file that's included by this header before this header is included. For example a previous class definition in another file may be missing the closing semicolon and the compiler's not tripping over the mistake until it gets to the `Game` destructor. – user4581301 Jul 11 '18 at 18:19

1 Answers1

0

You need to have written:

Game::~Game(){

}

somewhere at the bottom, outside the class.

Then it will compile fine :)

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103