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

forward class declaration and circular including

P: n/a
Hi, there was a post several days ago about using forward class
declaration to solve the circular including issue, today, one question
suddenly came into mind: which class should the forward class
declaration statement be in? suppose I have a class A and B, sample
code as following:

// A.h
#ifndef A_H
#define A_H

class B; // forward declaration

// define A here

#endif

// B.h
#ifndef B_H
#define B_H

#include B.h

// define B here

#endif

from the ListNode and List example in Deital book, I found if A is part
of B, say,ListNode is part of List, then the forward declaration
statement is in A. Is this the general rule? or we can randomly put the
forward declaration stmt in either class, and let the other to use the
#include ???

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


blueblueblue2005 schreef:
Hi, there was a post several days ago about using forward class
declaration to solve the circular including issue, today, one question
suddenly came into mind: which class should the forward class
declaration statement be in?


Both. The guideline is to use a forward declaration when possible,
and only use the #include if needed.

HTH,
Michiel Salters

Jul 23 '05 #2

P: n/a
> Both. The guideline is to use a forward declaration when possible,
and only use the #include if needed.


I tried to switch the classes which have the forward declaration and
#include stmt, it turned out that it works(no compiling error) only
when A has the forward declaration and B has the #include stmt. so not
Both, which will make a circular forward declaration.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.