S
sklett
I am trying to make a library that will read and write one of our text file
formats. It is a hierarchical structure and I have modeled the classes
after it. For example:
class Character
class Skeleton
class Keyframe
Where a Character has a vector of Skeleton objects and a Skeleton has a
vector of Keyframe objects. All of these classes are in separate h/cpp
files. I use typedef to define a type that represents a std::vector of the
various objects. I create these typedefs after the class declaration in the
h file.
I have run into a real nightmare with all these interrelated classes. I
have a mess of #include statements just trying to get everything to compile.
Some h files need a class prototype just to compile, even though I have
added the relevant class' h file. For example
//Character.h
#include "skeleton.h"
class Skeleton; // without this line, it won't compile because of
the use of Skeleton in the ctor of Character
class Character
{
Character(const Skeleton& skel);
}
Sometimes this doesn't work. It's so frustrating when I include the file of
the type being used and the compiler still doesn't know what it is. I know
that I'm supposed to limit #include statements in h files, but many of my
functions have parameters that use my various classes, so I need to. In
some rare cases, including a used class' h file in the cpp file of the class
that's using it will work, but it's very hit and miss. It just feels
totally random.
So, there is my sob story. Now I want to know what I'm doing wrong.
Assuming you were writing a static library with many interrelated files,
what are some general rules of tricks for header inclusion? I've tried to
think of it sequentially as the compiler might approach it, but this hasn't
helped.
I am using precompiled headers. I have included all my stl stuff, disabled
warnings, created macros, etc... but I haven't added any of my file headers,
this seems wrong.
Suggestions? Tips? Anything? I'm really stuck...
Thanks for reading,
Steve
formats. It is a hierarchical structure and I have modeled the classes
after it. For example:
class Character
class Skeleton
class Keyframe
Where a Character has a vector of Skeleton objects and a Skeleton has a
vector of Keyframe objects. All of these classes are in separate h/cpp
files. I use typedef to define a type that represents a std::vector of the
various objects. I create these typedefs after the class declaration in the
h file.
I have run into a real nightmare with all these interrelated classes. I
have a mess of #include statements just trying to get everything to compile.
Some h files need a class prototype just to compile, even though I have
added the relevant class' h file. For example
//Character.h
#include "skeleton.h"
class Skeleton; // without this line, it won't compile because of
the use of Skeleton in the ctor of Character
class Character
{
Character(const Skeleton& skel);
}
Sometimes this doesn't work. It's so frustrating when I include the file of
the type being used and the compiler still doesn't know what it is. I know
that I'm supposed to limit #include statements in h files, but many of my
functions have parameters that use my various classes, so I need to. In
some rare cases, including a used class' h file in the cpp file of the class
that's using it will work, but it's very hit and miss. It just feels
totally random.
So, there is my sob story. Now I want to know what I'm doing wrong.
Assuming you were writing a static library with many interrelated files,
what are some general rules of tricks for header inclusion? I've tried to
think of it sequentially as the compiler might approach it, but this hasn't
helped.
I am using precompiled headers. I have included all my stl stuff, disabled
warnings, created macros, etc... but I haven't added any of my file headers,
this seems wrong.
Suggestions? Tips? Anything? I'm really stuck...
Thanks for reading,
Steve