Re: forward declarations of gtkmm stuff



On 1/2/08, Murray Cumming <murrayc murrayc com> wrote:
>
> On Wed, 2008-01-02 at 10:06 -0600, Jonathon Jongsma wrote:
> > On 1/2/08, Naveen Verma <ernaveenverma gmail com> wrote:
> > > Hi,
> > >
> > > I am sorry but somehow I got confused, I could not understand, does it make
> > > any difference in compilation if we include other headers(like windows.h
> > > etc) in a header file(e.g. foo.h) or in its source file(e.g. foo.c ) or in
> > > both, because in my understanding headers usually have #ifdef in it so it
> > > doesn't matter whether we include once or twice, it will be included only
> > > once at compile time, and at least we need to include once somewhere either
> > > in source or header.
> > >
> > > -Br
> > > Naveen
> >
> > Yes, what you say is correct, but the point of forward-declaration is
> > somewhat different.  The point is not to prevent headers from being
> > included multiple times, but to prevent them from being included at
> > all if they're not absolutely necessary.  For example, say you have
> > the following setup:
> >
> > A.h
> > A.cpp
> > B.h includes A.h
> > B.cpp
> > C.h includes B.h
> > C.cpp
>
> However, this isn't the case when including a library such as gtkmm.
> gtkmm doesn't include your application's headers. I know that's not the
> point of your (helpful) explanation - I'm just saying it for the sake of
> the original question.

yes true, thanks for clearing that up.  In the case of a library like
gtkmm, the only real benefit you get from forward declaration is
speeding up compile times since the library headers will not be
changing regularly (unless you're running a distribution that updates
gtkmm very often)

-- 
jonner


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]