Re: [Dev-C++] Organisation of header files
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Nathan S. <cat...@do...> - 2003-07-09 02:01:55
|
I think, for each class you have a header file, so:
class1.h
class1.cpp
class2.h
class2.cpp
main.cpp
If class2 has data members based on a type of class1, i would only #inclu=
de
"class1.h" in class2.h. main.cpp would not have to include class1.h (i
think, i am still learning).
But if main uses object of type class1, you would have to #include
"class1.h" in main.cpp.
I look at my classes in a heirachial (sp?) structure, and only include th=
e
header files that they need.
Nathan.
----- Original Message -----
From: "Ioannis Vranos" <iv...@em...>
To: <dev...@li...>
Sent: Wednesday, July 09, 2003 10:42 AM
Subject: RE: [Dev-C++] Organisation of header files
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Michael Stather
> Sent: Tuesday, July 08, 2003 11:59 PM
> To: dev...@li...
> Subject: [Dev-C++] Organisation of header files
>
>
> Hi,
>
> I divide my classes in a .cpp-file and a
> header-file (as suggested).
> Now I=B4ve heard of 3 possibilities to organise the
> dependencies:
>
> 1. Include only one header file in the
> implementation file, and in this header file,
> beside the class declaration include all required
> headers
>
> 2. Include the header which are important for the
> public interface of the class in the .cpp-file,
> and those who are only important for the methods
> "inside" the class in its header file (sounds the
> most logical)
>
> 3. Don=B4t include any header-file in the
> class-header, but include them all in the
> .cpp-file (before the actual class-header)
>
> Which solution is the best? (Or perhaps a
> completely different solution)
>
> Thanks for your help!!
I have got a headache so here you go. For non-template classes:
1) You can place the definition of the class in all the files you use the
class, that is you can place it in a header file and include that header
file to all the .cpp files you use the class.
This means that for every change in the definition of the class, you will
have to recompile all the source code files which have the definition (th=
e
header).
2) Place the definition of the class in the header file except of the mem=
ber
functions (usually the large ones) that should be defined out of the
definition of the class:
Example:
---- myheader.h
class A
{
int s;
public:
A(int r):s(r) {}
void great_things() const;
};
--- myheader.cpp
#include "myheader.h"
void A::great_things() const
{
// ...
}
For every change in the .cpp file only, no other source code files is nee=
ded
to be recompiled.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|