Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > favoring forward class declaration over #include

Reply
Thread Tools

favoring forward class declaration over #include

 
 
Aaron Anodide
Guest
Posts: n/a
 
      08-01-2003
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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-01-2003
"Aaron Anodide" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Re-forward declaration of types which were already forward declared qazmlp C++ 1 02-15-2004 07:00 PM
forward declaration of a template class? Nobody C++ 2 02-12-2004 07:05 AM
Problem with class forward declaration Martin Eisenberg C++ 3 11-26-2003 12:05 AM
Class forward declaration Kevin Grigorenko C++ 6 09-15-2003 03:18 PM



Advertisments