53 lines
817 B
C++
53 lines
817 B
C++
|
// 重载运算符
|
||
|
#include <iostream>
|
||
|
#include <cstring>
|
||
|
#include <cstdlib>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
class Num
|
||
|
{
|
||
|
private:
|
||
|
int n;
|
||
|
|
||
|
public:
|
||
|
explicit Num(int n) : n(n)
|
||
|
{
|
||
|
}
|
||
|
bool operator>(int other)
|
||
|
{
|
||
|
return this->n > other;
|
||
|
}
|
||
|
bool operator<(int other)
|
||
|
{
|
||
|
return this->n < other;
|
||
|
}
|
||
|
bool operator>(Num &other)
|
||
|
{
|
||
|
return this->n > other.n;
|
||
|
}
|
||
|
bool operator<(Num &other)
|
||
|
{
|
||
|
return this->n < other.n;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
Num n1(atoi(argv[1])), n2(atoi(argv[2]));
|
||
|
if (n1 > 20)
|
||
|
{
|
||
|
cout << "n1 大于 20" << endl;
|
||
|
|
||
|
if (n1 < n2)
|
||
|
{
|
||
|
cout << "n1 小于 n2" << endl;
|
||
|
}
|
||
|
}
|
||
|
if (n1 > n2)
|
||
|
{
|
||
|
cout << "n1 大于 n2" << endl;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|