Hello all,
Am trying to move an antique C++ code base from gcc 3.2 to gcc 4.1, as I have run into a few issues. Of all the issues, the following is left me clueless (I guess I spent too much time with Java or I might have forgotten the basics of C++ :-P ).
I have a template class
template < class T > class XVector < T >
{
...
template < class T > T
XVector < T >::getIncrement ()
{
...
}
template < class T > int
XVector < T >::getValue (size_t index, T& value)
{
...
//The problematic line
value = (T) (first_value + getIncrement())
* (long) (index - first_index);
....
}
}
This class is based on the STL std::vector. I have a second class TypeValue and its defined as below which can hold one of int, long and their unsigned variants, float, double, std::string. Also overloads almost all possible operators.
class TypeValue
{
union
{
long* _int_value;
double* _real_value;
string* _text_value;
} _value;
TypeValue();
explicit TypeValue(long _long);
explicit TypeValue(int _int);
explicit TypeValue(unsigned long _ulong);
...
//similarly for all the remaining supported types.
TypeValue(const TypeValue& ) //Copy constructor
virtual TypeValue& operator=(const TypeValue &rhs);
TypeValue& operator+ (TypeValue& )const;
TypeValue& operator* (TypeValue& )const;
...
//For all the basic operators
operator long() const;
operator int() const;
operator unsigned long() const;
operator unsigned int() const;
...
}
And finally I have another class, lets call it the build_breaker, which creates an object as XVector < TypeValue > a_variable;
. Now when I compile this on gcc 3.2 this compiles without any problems. But when I try compiling this on gcc 4.1 I get errors saying ambigous overload for operator*
in the class XVector
and the candidates being
operator*(long int, long int) operator*(int, long int) operator*(long unsigned int, long int) operator*(unsigned int, long int) operator*(double, long int) operator*(float, long int)
If the compiler said it had problems finding a match for T * long, that would have made sense, but, why is it trying to typecast it to native type and then perform the arithmetic operation? Please help me on this.
Thanks in advance.