0

I'm writing a multi-file program in C++ (School project). Yesterday I ran into a rather odd issue. When I included one specific header file in my program, it refuses to compile. It gives me the error "missing ; before *" which indicates some of my class declared in other headers became undeclared or something like that. The header file I am including is including the header file is also including the header file I am including from. On the other hand, I am using the #if !defined(FILENAME_H) to avoid double including. It is also worth mentioning it is only one specific header file which causes my issues, and nothing is wrong with the defined/not defined/endif codes.

Martin
  • 2,606
  • 4
  • 24
  • 38
  • 1
    This [Q&A](http://stackoverflow.com/questions/14909997/why-arent-my-include-guards-preventing-recursive-inclusion-and-multiple-symbol) (especially the first question/answer) should help you – Andy Prowl Apr 21 '13 at 09:37
  • So what is the question? – juanchopanza Apr 21 '13 at 09:37
  • @AndyProwl I believe this answers my question, thanks :D – Martin Apr 21 '13 at 10:06
  • Answer to my issue is the first question on this post: http://stackoverflow.com/questions/14909997/why-arent-my-include-guards-preventing-recursive-inclusion-and-multiple-symbol – Martin Apr 21 '13 at 10:06

2 Answers2

0

Looks like you have something like this in problematic header:

class A
{

}

Without ; after class declaration. And once you include that header, it leads to errors later on.

alexrider
  • 4,449
  • 1
  • 17
  • 27
  • I am already including the header elsewhere, and the class has a ; after the end bracket. – Martin Apr 21 '13 at 09:43
  • @Martin Can you provide header in question than? – alexrider Apr 21 '13 at 09:44
  • @Martin: Your problem is most likely with the mutual inclusion. Please take a look at [this Q&A](http://stackoverflow.com/questions/14909997/why-arent-my-include-guards-preventing-recursive-inclusion-and-multiple-symbol) that I am linking in the comments to your question – Andy Prowl Apr 21 '13 at 10:03
0

Dude every header file should begin with

#ifndef NAMEOFFILE_H
#define NAMEOFFILE_H

and end with

#endif

This ensures that a header file is not included in your program more than once.

Also if your class is undeclared the i am pretty sure you must have missed

a semicolon at the end of curly bracket} after class defintion

Mohit Shah
  • 843
  • 1
  • 6
  • 20
  • The OP is mentioning that the include guards are there. The compiler error is misleading and usually results from mutual header inclusion. It is all explained [here](http://stackoverflow.com/questions/14909997/why-arent-my-include-guards-preventing-recursive-inclusion-and-multiple-symbol) – Andy Prowl Apr 21 '13 at 10:04