[Insight-developers] IRIX64-6.5-CC-n32-Continuous errors and
CastImageFilter (declaring specializations of member functions)
Brad King
brad . king at kitware . com
Mon, 26 Aug 2002 09:07:11 -0400 (EDT)
Jim,
> Looking further at this... Why even have this as a class? All it has is
> a static member function. There is no instance data or regular member
> functions.
> Why not have this be a templated or just an overloaded (regular not
> class) function?
> > itk::fem::GenerateMesh<TElementType>::Rectangular(const
> > itk::fem::GenerateMesh<TElementType>::ElementType *,itk::fem::Solver
> > &,itk::fem::GenerateMesh<TElementType>::VectorType
> > &,itk::fem::GenerateMesh<TElementType>::VectorType
> > &,itk::fem::GenerateMesh<TElementType>::VectorType &)' :
MSVC6 has problems with code like this:
template <typename T> T* foo(int, float);
because T must be specified to call the function, and cannot be deduced
from the function arguments. We are supposed to be able to call the
function like this:
foo<char>(1, 3.4);
but it doesn't compile with MSVC6. There are two work arounds of which
I'm aware. The first is to change the declaration of foo to include T in
its interface:
template <typename T> struct Dummy {};
template <typename T> T* foo(int, float, Dummy<T>* =0);
This will make the compiler happy even when the third argument is left as
the default, and the above call will work.
The other fix is to put the template arguments on a class:
template <typename T>
struct Foo
{
static T* foo(int, float);
};
Foo<char>::foo(1, 3.4);
Now the compiler has no problem with finding the template arguments. One
can also define a set of overloads to foo inside Foo without having to
duplicate the Dummy<T>* =0 trick on every function.
-Brad