[Bf-committers] problems with C++
Jonathan Merritt
j.merritt at pgrad.unimelb.edu.au
Tue Oct 4 08:29:28 CEST 2005
Nathan Letwory wrote:
>With only template class SpTemp<int> it works for msvc too, but adding
>template class SpTemp<double> makes it choke on it. (Yes, I added the
>extra line also to where the <int> is). Additionally, it is not really
>helpful to use such a class if you have to declare *every* templated usage
>in the implementation files, thus kinda defeating the purpose of templated
>classes...
>
Hmm... it's a bit odd that it should work for one case but not two. I'm
running Linux only though, so I can't test with anything more than gcc.
I agree that having to declare every template usage does make things
more difficult, but it doesn't completely defeat the purpose of
templates; afterall, you don't have to re-specify the *entire* class,
under some different name, for each combination of types, you just add a
single line to achieve that effect. In most scenarios I've seen, a
final source tree will only use very limited number of combinations of
template parameters. If the number is excessive, you could even
generate them using a script to produce all the required combinations.
Obviously, it's far far less useful for a library of templated classes! :-)
Let's see whether the C++ experts have any suggestions. This was only
one idea; something I've used in the past (on my own internal, gcc-only
projects) to avoid having enormous header files included with each *.cpp
file.
Jonathan.
More information about the Bf-committers
mailing list