Could it be something wrong with Visual C++ 2010 Express |
As a general rule, if you ever find yourself thinking "it could be a problem with my compiler", then you are almost certainly wrong. I'm paraphrasing that from something someone else posted here a few weeks ago, but it's true. Something like MSVC will have had more man-hours put into testing than you or I will ever spend coding in our entire lives. Unless you're making use of some obscure and advanced language feature that's not in the code you've posted - say, some new C++11 feature - the chance of it being a compiler bug is negligible.
If I try to create an object of menu manager in another class I get the same error and if I comment the code it compiles fine. |
If you're creating a MenuManager object in another bit of code, then presumably you're also including MenuManager.h in that other code, which means that you're including the same other header files that MenuManager.h includes. So if there's an error in one of those files, you'll see it there too.
What exactly is it that you comment out to make it work?
Would it not show an error if I was missing a semi-colon? |
C++ syntax is very flexible. You can nest statements inside other statements, nest code blocks inside code blocks, and generally come up with all sorts of ways to use the language that, when parsed by the compiler on a line-by-line basis, are legal in C++. The compiler might - totally legitimately - not know that you've missed a semicolon, or a close-brace, from any given line of your code. It's not the compiler's job to guess what you meant to do, only to check that each line of C++ is legal and if so to convert it to machine code.
Thus, it might be that the C++ you have written before line 16 of titleScreen.h - including the header files it includes - might be legal, but due to a mistake on your part, might not constitute a complete definition of the MenuManager type. This means that, until your code tries to actually use the MenuManger type on line 16 of titleScreen.h, the compiler thinks your code is legal. It's only at that point that the compiler says "Wait, what? I don't know yet what MenuManger is!" and reports an error.
In my experience, this is most likely to mean a missing semicolon, or that something is wrong with your braces. I've just looked over MenuManger.h and the fragment of titleScreen.h again, and still can't see anything wrong with them, so the problem must lie within some of the code that those files include that you haven't shown us.
Could Circular Dependencies of header files cause these errors? |
It's possible, but in my experience that's more likely to result in error messages saying that there are multiple definitions of symbols.
In any case, since you're using
#pragma once
to protect against multiple inclusion in MenuManager.h, I'm assuming that you've already double-checked that you're doing it in all the header files included in MenuManager.h.