Invalid use of incomplete type / forward declaration?

You probably have got a loop in your includes in such way that CPlayerChar doesn't know who really is CEntity, it just knows that it exists, but doesn't know what is it If you remove the "class CEntity" declaration, you will see that GCC will complain that CEntity doesn't exists You must check that nothing that CEntity includes include CPlayerChar.

You probably have got a loop in your includes in such way that CPlayerChar doesn't know who really is CEntity, it just knows that it exists, but doesn't know what is it. If you remove the "class CEntity" declaration, you will see that GCC will complain that CEntity doesn't exists. You must check that nothing that CEntity includes include CPlayerChar.

Thanks, that last line of yours must be it. CEntity includes another file which includes CEntity and CPlayerChar. Now I just need to find a workaround.

– rivon Aug 8 at 21:52.

You have a circular inclusion in your header files. But without all the header files we will not be able to fix it. I would start here.

#include "CAnimation. H" Looking at your header you don't actually need this. You only use CAnimation by reference or pointer so the forward declaration you have should be sufficient.

Move the include into the source file (ie out of the header). The next place I would look is: #include "global_includes. H" Any global includes that are included in a header file better be very simple.

Should only contain simple types and not include any other header files (unless they are just as simple). Anything complex is going to lead to problems with circular dependencies. General rule of thumb A header file should only include header files that it absolutely needs.

Otherwise they should be included from the source file. You only absolutely need a header file if it defines a class that is used as a parent class you have members objects of that class, or you use parameter objects of that class. I use the term object to distinguish from references or pointers.

If you are using these you do not need to include the header file. You only need to do a forward declaration.

You have to ensure that the full definition of the class CEntity is visible at the point where you define the class CPlayerChar. (So check your inclusions. ) This is because you can only inherit from fully defined classes, but not from just forward-declared ones.

The only time you can get away with forward-declarations in place of full definitions is when you make pointers or references to a type, but only if you never access any of its members, or (thanks to @Alf) when declaring a function with incomplete return type.

1 forward declarations are a bit more powerful than you appear to indicate. For example, if T is an incomplete type, then declaring a function T foo() is perfectly all right. In order to call it you need to have T completed (unless T is the special type void, which formally is an incomplete type that can never be completed), but that's a different issue.

:-) – Alf P. Steinbach Aug 8 at 22:10 @Alf: Thanks! That's useful.

What about function parameters, can those be incomplete? – Kerrek SB Aug 8 at 22:17 yes ............ – Alf P. Steinbach Aug 8 at 23:24.

You only use CAnimation by reference or pointer so the forward declaration you have should be sufficient. Move the include into the source file (ie out of the header). Any global includes that are included in a header file better be very simple.

Should only contain simple types and not include any other header files (unless they are just as simple). Anything complex is going to lead to problems with circular dependencies. A header file should only include header files that it absolutely needs.

For Facility* f = new Facility() you need a full declaration, not just forward declaration.

For Facility* f = new Facility(); you need a full declaration, not just forward declaration.

– robev Apr 4 at 19:34 @robev Including the facility. H should work just fine, unless there are other errors. – Let_Me_Be Apr 4 at 19:36 @robev - Things will clear up if you show Foo class header and it's source file.

– Mahesh Apr 4 at 19:36 1 Yes, you do. Including facility. H only brings in the forward declaration of Area.

But since you're using an Area method you need to bring in the full declaration of Area. Which given your setup means you have to include area.h. – QuantumMechanic Apr 4 at 19:42 1 @robev If you want area, include area, if you want facility, include facility, it's that simple.

– Let_Me_Be Apr 4 at 19:42.

Did you #include both area. H and facility. H in foo.

Cpp (assuming this is the file where you get the error)?

– robev Apr 4 at 19:35 1 Yes, since you are calling member functions for both Area and Facility instances in your code, you have to. – Frank Schmitt Apr 4 at 19:39.

To clarify: a forward declaration allows you to operate on an object if very limited ways: struct Foo; // forward declaration int bar(Foo* f); // allowed, makes sense in a header file Foo* baz(); // allowed Foo* f = new Foo(); // not allowed, as the compiler doesn't // know how big a Foo object is // and therefore can't allocate that much // memory and return a pointer to it f->quux(); // also not allowed, as the compiler doesn't know // what members Foo has Forward declarations can help in some cases. For instance, if the functions in a header only ever take pointers to objects instead of the objects, then you don't need to #include the whole class definition for those objects. This can improve your compilation times.

But the implementation for that header is almost guaranteed to need to #include the relevant definition because you're likely going to want to allocate those objects, call methods on those objects, etc. And you need more than a forward declaration to do that.

Forward declarations can help in some cases. For instance, if the functions in a header only ever take pointers to objects instead of the objects, then you don't need to #include the whole class definition for those objects. This can improve your compilation times.

But the implementation for that header is almost guaranteed to need to #include the relevant definition because you're likely going to want to allocate those objects, call methods on those objects, etc. and you need more than a forward declaration to do that.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions