By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

favoring forward class declaration over #include

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Aaron Anodide" <an*****@hotmail.com> 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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.