473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

static library woes

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
Dec 1 '05 #1
3 1041
Just realized I posted this in .net NG, sorry, I will go post in the
"dangerous" C++ NG :)
"sklett" <as**@fkd.com> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
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

Dec 2 '05 #2
"sklett" <as**@fkd.com> wrote
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. That's the correct way. A class type X must be complete before
std::vector<X> is instantiated.
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


You probably don't have the appropriate include guards. Typically,
you'd say
// start-of-file
#ifndef CHARACTER_H_INCLUDED
#define CHARACTER_H_INCLUDED
// definitions
#endif // end-of-file

You can then simply put the appropriate includes without
running into cyclic dependencies.

The most straightforward way is probably to have a separate
header with forward declarations and possibly (enums &
typedefs).

Make sure it doesn't include anything else and you include
it as the first file from every other header.

Then only add #include in headers if complete objects are
required.

In your case
Character.h includes forward.h, Skeleton.h
Skeleton.h includes forward.h, Keyframe.h
Keyframe.h includes forward.h

-hg
Dec 2 '05 #3
Thank you Holger,

I missed this message before. I like your idea about using a forward file.
"Holger Grund" <ho**********@remove.ix-n.net> wrote in message
news:Ow**************@TK2MSFTNGP11.phx.gbl...
"sklett" <as**@fkd.com> wrote
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.

That's the correct way. A class type X must be complete before
std::vector<X> is instantiated.
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


You probably don't have the appropriate include guards. Typically,
you'd say
// start-of-file
#ifndef CHARACTER_H_INCLUDED
#define CHARACTER_H_INCLUDED
// definitions
#endif // end-of-file

You can then simply put the appropriate includes without
running into cyclic dependencies.

The most straightforward way is probably to have a separate
header with forward declarations and possibly (enums &
typedefs).

Make sure it doesn't include anything else and you include
it as the first file from every other header.

Then only add #include in headers if complete objects are
required.

In your case
Character.h includes forward.h, Skeleton.h
Skeleton.h includes forward.h, Keyframe.h
Keyframe.h includes forward.h

-hg

Dec 9 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
2
by: free2cric | last post by:
Hi, I have two c++ static libraries say A.lib and B.lib. I am creating third static library C I create project in microsoft visual studio as win32 static library. I go to project-> settings ->...
3
by: mpatnam | last post by:
I have an executable which links to a static library (.a). I want to provide a hook by overriding a function part of this static library. Eg: I have a function "int blkstart(int i)" in this static...
4
by: newest newbie | last post by:
I'm new to using c#, but what I'm trying to do is create a library control containing a form which in turn contains a Windows application that I have defined in another library. I'm able to do...
8
by: Robert A Riedel | last post by:
I have an application that requires a DLL and an executable that uses the DLL, both of which were implemented in Visual C++ using unmanged code. Both the executable and the DLL are linked with...
5
by: Gerhard Menzl | last post by:
When creating a Managed C++ DLL using the Visual Studio 7.1 Solution Explorer (by selecting Add New Project and then either choosing Class Library (.NET) or Windows Control Library (.NET)), the IDE...
15
by: Notre Poubelle | last post by:
Hello, I have a large legacy MFC application. As is typical, there is an executable along with several MFC DLLs. One of these DLLs is created by staticly linking in many libraries resulting in...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.