#include<iostream>
usingnamespace std;
template <class S>
class TestFunctions
{
public:
bool Compare2( S * s1, S * s2) { return *s1 == *s2; }//;
//not necessary, your compiler will generate this from the above,
//when it sees TestFunctions< double > a; inside main.
//bool Compare2( double * t1, double * t2) { return *t1 == *t2; };
//don't make this a static function
bool STest( S s1, S s2 )
{
//pass S* here, as your Compare2 expects
//Compare2( s1, s2 );
return Compare2( &s1, &s2 );
}
};
int main( int argc, char * argv[])
{
double d1, d2;
TestFunctions< double > a;
//let's get some values first...
cout << "enter 2 doubles:\n";
cin >> d1 >> d2;
//...and then add a way to check the result
if (a.STest( d1, d2 ))
cout << "they are equal!" << endl;
else
cout << "they are not equal!" << endl;
cin.get();
cin.get();
return 0;
}
First of all ,ur functions :
bool Compare2( S * s1, S * s2) { return *s1 == *s2; };
bool Compare2( double * t1, double * t2) { return *t1 == *t2; };
will casue ambiguity when u pass <S> as <double>,as there would be 2 functions to map to ...
hence the compiler is giving an error that:
cannot find match.
Once you fix this you will again get an error as you are passing object by value,where as function will accept addresses.