template<class T1, typename T2
>
class Compare
{
public:
Compare(T1 x
= 0, T2 y
= 0)
:x(x
), y(y
)
{
}
bool isEqual()
{
if (x
== y
)
return true;
return false;
}
T1
getX();
void setX(T1 x
);
private:
T1 x
;
T2 y
;
};
template<class T1, typename T2
>
T1 Compare
<T1
, T2
>::getX()
{
return x
;
}
template<class T1, class T2>
void Compare
<T1
, T2
>::setX(T1 x
)
{
this->x
= x
;
}
template<class T1>
class Compare<T1
, const char *>
{
public:
Compare(T1
*x
= 0, const char *y
= 0)
:x(x
), y(y
)
{
}
bool isEqual()
{
if (!strcmp(x
, y
))
return true;
return false;
}
const char* getX();
void setX(const char* x
);
private:
T1
*x
;
const char *y
;
};
template<class T2>
class Compare<const char *, T2
>
{
public:
Compare(const char *x
= 0, T2
*y
= 0)
:x(x
), y(y
)
{
}
bool isEqual()
{
if (!strcmp(x
, y
))
return true;
return false;
}
const char* getX();
void setX(const char* x
);
private:
const char *x
;
T2
*y
;
};
void main()
{
Compare
<int, int> com1(10, 20);
com1
.setX(20);
cout
<< com1
.isEqual() << endl
;
Compare
<string
,string
> com2("jack", "jack");
cout
<< com2
.isEqual() << endl
;
Compare
<const char*, const char*> com3("jack", "jack");
cout
<< com3
.isEqual() << endl
;
}
转载请注明原文地址: https://www.6miu.com/read-35294.html