Ian Collins wrote:
> How to you unit test as leaf class?
Assuming this is a typo for "how do you unit test a leaf class," I
think you've hit upon the major flaw/limitation in this approach.
Every class which one is interested in unit-testing (which should be
basically every class) has at least one class which is interested in
including the header for that class so as to use it. Unless one does
something funky like put the test code and production code in the same
compilation unit. Either by putting them both in the same literal
file, or by #including one implementation file from the other (possibly
with an #if TESTING guard around the #include, going in one direction).
Any other ideas to get around this limitation?
> > Oh, and there are some other solutions to the template instantiation
> > problem, by the way.
> >
> Use a compiler that doesn't suffer from it
That's one. Individual programmers on a team/within a company are
frequently not entirely at liberty to simply choose whatever compiler
they like for production code, though. But the FAQ mentions some other
options, which I'm sure you've read, and which I've used (with minor
variants of my own devising) to good effect. The practice of
#including the implementation files for templates has some interesting
consequences, like enabling easy control of the size and number of
one's compilation units.
> Well it's not an abuse, but if you are looking to simplify things -
> seeing as some compilers can find template definitions in source files,
You are referring to the "export" keyword, right?
> why can't C++ compilers use search rules to find header files when they
> encounter a class? If you're not sure what I'm on about, google for
> "php autoload".
Well, I don't think this has very much to do with template exporting,
but it could be readily accomplished (modulo a reasonable approach to
disambiguation) with an added preprocessor step. Use the scripting
language of your choice. I had a peek at php autoload -- doesn't look
like a model that would be doable with the C++ preprocessor as-is.
Luke