Hi, everybody:
What's the way to overload template types under gcc4.1.0? Our following
code snippet works fine under gcc3.2 but get errors under gcc4.1.0.
MScalar.h
template<class TIntegral, class TSize>
class MScalar {
TIntegral value_d;
public:
// method: mod
TIntegral mod(TIntegral arg2) {
return mod(value_d, arg2);
}
// method: mod
TIntegral mod(TIntegral arg1, TIntegral arg2) {
return (value_d = arg1 % arg2);
}
private:
// method: mod
template<> double MScalar<double, float64>::mod(double arg1, double
arg2) {
return arg1;
}
}
Basically, we need to check the input type of mod(arg1, arg2). If arg1
and arg2 are both double, we just return arg1;
Under gcc4.1.0, it is fine to compile it to object code, but it will get
following error message when another class Boolean links it into
executable file.
-------error message-----
In function `MScalar<double, double>::mod(double,
double)':diag_param_00.cc:(.text+0x30): multiple definition of
`MScalar<double, double>::mod(double, double)'
Boolean_diag.o:diagnose_class.cc:(.text+0x30): first defined here
Please give some advise, guys. This template problem is killing me :(
--
Kind Regards,
Tao Ma