1

I have a project with multiple files including main.cpp and two headers. Both headers have an error at the line with class name declaration. Building any of the files or project as a whole gives no errors or warnings. The program itself runs correctly.

I'm using CodeLite IDE and GCC compiler.

What can be a reason for such behaviour and could it lead to any issues in the future?

#include <Creature.h>
#include <Party.h>

int main() { 
    // Does something with the stuff from header files.
    return 0;
}

Inside Creature.h:

#pragma once

class Creature { // Error: expected ';' after top level declarator
    // something
};

Inside Party.h:

#pragma once

class Party { // Error: expected identifier or '('
    // something
};
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
trofchik
  • 87
  • 1
  • 7
  • 2
    Is that actually the entirety of your code? Based on the error, my guess is that a type somewhere isn't being terminated with a semi-colon. – Stephen Newell Sep 04 '20 at 12:49
  • @Stephen Newell Yes it is the entirety of program minus the content of the brackets. – trofchik Sep 04 '20 at 13:53

1 Answers1

1

Your IDE thinks that the header files are written in C (where class is not a keyword and so Creature is a declarator), because you gave them the conventional extension .h used to indicate that. Don't do that: use .hh, .hpp, or .hxx for C++ header files so that tools (and humans) know what you're writing without having to understand the file.

Davis Herring
  • 36,443
  • 4
  • 48
  • 76