博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
运算符重载
阅读量:4556 次
发布时间:2019-06-08

本文共 1310 字,大约阅读时间需要 4 分钟。

#include <stdio.h>

#include "stdafx.h"
struct BigNumber {
private:
    unsigned int low;
    unsigned int high;
public:
    BigNumber(int x, int y)
    {
        this->low = x;
        this->high = y;
    }
    BigNumber operator ++();
    void operator =(const BigNumber &n);
    bool operator >(const BigNumber &n);
    bool operator ==(const BigNumber &n);
    void print();
};
BigNumber BigNumber::operator ++()
{
    if(this->low == 0xFFFFFFFF) {
        this->low = 0;
        this->high++;
    } else
        this->low++;
    return *this;
}
void BigNumber::operator =(const BigNumber &n)
{    
    this->low = n.low;
    this->high = n.high;
}
bool BigNumber::operator >(const BigNumber &n)
{
    if (this->high > n.high)
        return true;
    else if (this->high < n.high)
        return false;
    else if (this->low > n.low)
        return true;
    else if (this->low <= n.low)
        return false;
}
bool BigNumber::operator ==(const BigNumber &n)
{
    if (this->high == n.high && this->low == n.low)
        return true;
    else
        return false;
}
void BigNumber::print()
{
    printf("low: %u, high: %u\n", this->low, this->high);
}
    
int main(int argc, char* argv[])
{
    //BigNumber n(1, 2);
    BigNumber n(0xFFFFFFFF, 2);
    n.print();
    n++;
    n.print();
    BigNumber n1(1, 2);
    BigNumber n2 = n1;
    n2.print();
    printf("n1 %s n2\n", n1 == n2 ? "==" : "<");
    n2++;
    printf("n1 %c n2\n", n1 > n2 ? '>' : '<');
    getchar();
    return 0;
}

转载于:https://www.cnblogs.com/roadmap99/p/6771510.html

你可能感兴趣的文章
MySQL 删除数据库
查看>>
JavaScript 字符串(String) 对象
查看>>
How to use VisualSVN Server and TortoiseSVN to host your codes and control your codes' version
查看>>
微信小程序picker组件 - 省市二级联动
查看>>
Dynamics CRM 给视图配置安全角色
查看>>
Eclipse修改已存在的SVN地址
查看>>
(转)使用 python Matplotlib 库绘图
查看>>
进程/线程切换原则
查看>>
正则表达式语法
查看>>
20165301 2017-2018-2 《Java程序设计》第四周学习总结
查看>>
Vue的简单入门
查看>>
urllib 中的异常处理
查看>>
通过SQL Server的扩展事件来跟踪SQL语句在运行时,时间都消耗到哪儿了?
查看>>
比较:I/O成员函数getline() 与 get()(第二种用法)的用法异同
查看>>
7.内部类(一)之详解内部类
查看>>
1.messager消息提示框
查看>>
C teaching
查看>>
分隔指定内容,提取章节数
查看>>
this point
查看>>
验证登录信息是否合法
查看>>