默认, operator overload被继承时时隐藏的.
代码
//------------------------------------------------------
class IComparor
{
public:
virtual int operator()(int x, int y) = 0;
};
//------------------------------------------------------
class ComparorA : public IComparor
{
public:
using IComparor::operator();
int operator()(int x, int y)
{
return x < y ? -1
: x > y ? 1
: 0;
}
};
//------------------------------------------------------
class ComparorB : public IComparor
{
public:
using IComparor::operator();
int operator()(int x, int y)
{
return x < y ? 100
: x > y ? -100
: 0;
}
};
//------------------------------------------------------
class IComparor
{
public:
virtual int operator()(int x, int y) = 0;
};
//------------------------------------------------------
class ComparorA : public IComparor
{
public:
using IComparor::operator();
int operator()(int x, int y)
{
return x < y ? -1
: x > y ? 1
: 0;
}
};
//------------------------------------------------------
class ComparorB : public IComparor
{
public:
using IComparor::operator();
int operator()(int x, int y)
{
return x < y ? 100
: x > y ? -100
: 0;
}
};
//------------------------------------------------------
使用:
IComparor* comparor = new ComparorB();
int r1 = comparor->operator()(5, 6);
int r2 = (*comparor)(5, 6);
int r1 = comparor->operator()(5, 6);
int r2 = (*comparor)(5, 6);