|
From: Noorez K. <lor...@ho...> - 2006-01-21 21:11:44
|
I'm having trouble using a template that i have.
I'm making a template class, and overloaded the comparison operator >.
The function below should compare the type of my class, with the template
parameter T. I tested it with int as the type for the template and attempted
to this comparison
basic_bignumber<int,0,9> value(15);
if( value > 3 )...
but the compiler complained and said there was no match for operator>
for value>3. Anyone have any ideas with whats wrong?
template< typename T, int __low_value, int __high_value >
bool basic_bignumber<T, __low_value, __high_value>::operator>( T& test )
{
basic_bignumber< T, __low_value, __high_value > compare( test );
int pos1 = 0, pos2 = 0;
for( int i = 0; i < value_size; i++ )
{
if( value[ i ] == 0 ) continue;
pos1 = i;
break;
}
for( int i = 0; i < compare.value_size; i++ )
{
if( compare.value[ i ] == 0 ) continue;
pos2 = i;
break;
}
if( pos1 == 0 && pos2 == 0 ) return false; //all were zero's
else if( pos1 != 0 && pos2 == 0 ) return true; //if this had something
//while the other didn't
else if ( pos1 == 0 && pos2 != 0 ) return false; //if this didn't have
//anything, while the
other
//did
//if the the total value_size - (pos+1) is then compare, there
//are more values, so this would be greater...
if( value_size-(pos1+1) > compare.value_size-(pos2+1) ) return true;
//so if both the pos's are the same and the value's are both of
//the same size...check each individual digit...
bool greater = true;
for( int i = pos1; i < value_size; i++ )
{
if( value[ i ] < compare.value[ i ] ) greater = false;
else continue;
}
return greater;
}
_________________________________________________________________
Take advantage of powerful junk e-mail filters built on patented Microsoft®
SmartScreen Technology.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.
|