Hey,
The code tags are fine now, much more pretty this way, yes?
You still get compilation errors because when you specialize your template, the formal parameters have different types. In your template definition you have:
1 2
|
template< typename T >
T maximum( const T &first, const T &second )
|
And when specializing you have:
1 2
|
template<>
string maximum<string>(char *first, char *second)
|
Your specialization doesn't have const char*& type parameters, they are just char* type parameters.
And you may want to write your specialization like this:
1 2
|
template<>
char* maximum<char*>(char*& first, char*& second)
|
String documentation:
http://www.cplusplus.com/reference/string/string/
Operator overload documentation:
http://www.cplusplus.com/doc/tutorial/classes2/
http://msdn.microsoft.com/en-us/library/5tk49fh2%28v=vs.80%29.aspx
If you overloaded operator + for objects, other operators work just the same, only that comparison operators (like > or ==) may return bool since it's a true/false context for these type of operators.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
using namespace std;
class A
{
private:
int _member;
public:
A(int member): _member(member) { }
bool operator < (const A& other)
{
return (this->_member < other._member);
}
};
int main()
{
A object1(2), object2(3);
if (object1 < object2)
cout<<"2 is smaller than 3"<<endl;
else
cout<<"3 is smaller than 2"<<endl;
return 0;
}
|