favoring forward class declaration over #include

A

Aaron Anodide

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
 
V

Victor Bazarov

Aaron Anodide said:
[..] 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top