A New Krazy Checker for #include

Andras Mantia amantia at kde.org
Mon Apr 9 12:53:18 BST 2007


On Sunday 08 April 2007, Cyrille Berger wrote:
> > > Other ideas that I may implement one day (or maybe someone will
> > > do me): - if including an installed header, always use #include
> > > <foo.h>, not "foo.h" - foo.cpp should always include its own
> > > header foo.h first
> >
> > What is the reason for this?
>
> that way you are certain that "foo.h" can be include in a file
> without the need of including an other header. For instance:
> foo.h contains:
> class myWidget : public QWidget
> {};
> And in foo.cpp:
> #include<QWidget>
> #include "foo.h"
>
> build, but each time you want to include foo.h you also have to
> include QWidget, it's an easy example, but it's annoying to have to
> track headers.

And how will this be avoided by using < >? 

The solution for the above problem is that in the implementation files 
always include first your own headers, then the KDE headers and at last 
the Qt headers. Or at least always start with the header files 
corresponding to the implementation.
This way you will find that QWidget is not included in the foo.h when 
foo.cpp is compiled.

Andras

-- 
Quanta Plus developer - http://quanta.kdewebdev.org
K Desktop Environment - http://www.kde.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070409/001bac71/attachment.sig>


More information about the kde-core-devel mailing list