VS C++ 2010 Express problems (IDE/header files HELL ?)
I almost finished writing the first draft of my game's logic engine which is entity / component based. It's not perfectly based on that philosophy, but I also think that how the implementation is done differs from person to person. I'm writing in C++ using OOP, STL and virtual functions. Yes, I know that virtual functions may be slow but it's not an exercise for doing something very fast, just a logic engine which can be easily extended and easily understood by others (everything is also comment开发者_JAVA百科ed). It's just an exercise of 'software design' by a newbie to game developing if you may wish to call it that way.
My first draft is almost complete, the core services (various inits, directX, etc) are separated from the game logic and are ready to be used. I'm just trying to finish the logic engine before I can make my first prototype game (I think about an isometric ARPG). The GL engine is built like a tree of classes, starting at the top with the basic abstract class "Entity" and deriving from it more and more specific classes. There are no more than 3 or 4 levels of inheritance anywhere for good design reasons.. I think.
But I may have a serious problem: in certain classes in which I declare as member variables objects of another class, this happens: after the IDE kicks in and analyzes what I've written, it underlines those specific member variable's type (the class name) and it says it isn't declared anywhere. Then after a split of a second, the red underline disappears and it says it's ok and declared (o.O) IT HAPPENS AGAIN AND AGAIN everytime it analyses the code. This happens also in another class with another type of class. Just to be clear, I did include all the relevant headers and it SHOULD know about the type's declaration and where is it done.
Also, if I try to compile, it gives me gl_nonrenderableentity.h(21): error C2143: syntax error : missing ';' before '*'
and gl_nonrenderableentity.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
in pairs for each offending variable.
I know that the cause of this is not finding it's type anywhere (which strangely, the IDE finds, almost a second after each analysis). Sometimes those errors would be duplicated in the compiler's output and after tweaking a little how the headers where included, I get only one copy per variable (and it still doesn't makes sense, I'm using include guards.. doesn't VS 2010 Express understand pragmas ?)
I think it may be a header problem, but the most intriguing thing for me is: why the hell the IDE underlines the variable's type with red, saying it can't find it and after a second or two it finds it, no more problem, but when I compile all the project it gives me the former mentioned errors above.
Every time I had a problem, I researched and found a fix on my own, even problems with the IDE (the famous msbuild bug). But I just can't figure this out and I need the help of the veterans. Anyone has a clue of why the IDE is reacting like that ? The disappearing red underline after each analysis of the IDE must mean something. I know this happens with new variables when you write until the IDE finds their declarations, but it's only once and then it's ok no matter what.. with those 2 specific classes, it always does again and again this (and those are the only ones having this problem). Other member variables from other classes don't have this problem.
Thank you. Sorry for the long post, but I've tried making myself clear as hard as I could. If anyone wants any more information, please..
SOLVED
It was a circular reference problem, just use a forward declaration and you're fine.
The only reason I can think of is a circular reference, and even though it may not be immediately evident, a simple way to check (and possibly fix) this is to add a forward declaration for the other class:
class NonRenderableEntity;
class Action:public NonRenderableObject
{
...
NonRenderableEntity *userEntity;
...
};
Also, don't take the IntelliSense checking (red underlines) too seriously -- it's not perfect and can get confused, especially with complex references such as this.
Update: Circular references won't cause a problem as long as you only use pointers to objects. Because a pointer's size is independent of the actual object, the compiler can allocate a pointer beforehand without problems. In languages such as C#, objects are always manipulated via references (pointers) so this problem doesn't surface.
精彩评论