favoring forward class declaration over #include

Discussion in 'C++' started by Aaron Anodide, Aug 1, 2003.

  1. I ran into a wierd problem today where a case of circular includes caused my
    build to completely break. All my classes are spit out by a class wizard
    with "#pragma once" in the header. I thought this was equiv with the
    standard #ifndef scheme.

    Anyway, instead of figuring out exactly what went wrong (because after an
    hour all I can come up with is there was a cycle), I decided to use forward
    declarations, so everywhere I used to have:

    #include "Foo.h"

    I now have:

    class cFoo;

    My question is: is this a standard practice, to use forward declarations
    instead of #include? It seems more efficient to me, unless you are callling
    a method of the class of course, but that's only when you inline something
    right in the header.

    - Aaron Anodide
     
    Aaron Anodide, Aug 1, 2003
    #1
    1. Advertising

  2. "Aaron Anodide" <> wrote...
    > [..] I decided to use forward
    > declarations, so everywhere I used to have:
    >
    > #include "Foo.h"
    >
    > I now have:
    >
    > class cFoo;
    >
    > My question is: is this a standard practice, to use forward declarations
    > instead of #include? It seems more efficient to me, unless you are

    callling
    > a method of the class of course, but that's only when you inline something
    > right in the header.


    It's common, if that's what you mean under "standard practice".
    It reduces dependencies between files and speeds up compilation.

    Victor
     
    Victor Bazarov, Aug 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Grigorenko

    Class forward declaration

    Kevin Grigorenko, Sep 15, 2003, in forum: C++
    Replies:
    6
    Views:
    6,725
    Kevin Grigorenko
    Sep 15, 2003
  2. Martin Eisenberg

    Problem with class forward declaration

    Martin Eisenberg, Nov 25, 2003, in forum: C++
    Replies:
    3
    Views:
    4,632
    Martin Eisenberg
    Nov 26, 2003
  3. Nobody
    Replies:
    2
    Views:
    49,036
    Nobody
    Feb 12, 2004
  4. qazmlp
    Replies:
    1
    Views:
    603
    Jonathan Turkanis
    Feb 15, 2004
  5. Replies:
    3
    Views:
    586
Loading...

Share This Page