Templates: Code organization and forward declarations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rune Allnor

    #1

    Templates: Code organization and forward declarations

    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
Working...