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

Templates: Code organization and forward declarations

P: n/a
Hi all.

I have these classes, implemented as templates in header files.
Right now I have one file per class, where both the declarations
and implementations of one class are located in each file.

I would like to apply the visitor pattern to some of these classes.
One of the technicalities behind the visitor pattern is that one
needs forward declarations of classes, since there are two
class hierarchies which refer to each other.

In C++ one can refer to a yet undeclared class in one class'
*declaration*, but one can't refer to undeclared classes in the
*implementation*. Since the declaration and implementation
of my classes reside in the same file, my nice system breaks
down.

Or I need to set up a very entangled network of declarations
and implementations, which at the end *might* compile *if*
all the dependencies are carefully orchestrated. Which in turn
means that all classes need to know about all the other classes,
which ultimately destroys the nice modular class hierarchy I
have right now.

One tempting conclusion from all this is that templates don't
go well with forward declarations *and* a modular design.
This seems a bit too 'over the top' to be accepted just like
that, so am I overlooking something?

Rune
Sep 24 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.