首页 > 其他 > 详细

operator

时间:2018-07-15 10:15:09      阅读:127      评论:0      收藏:0      [点我收藏+]

例1,最简单的情况,重载==,以判断两个对象是否相等

#include "stdafx.h"
#include <iostream>
using namespace std;

class person
{
private:
    long id;
public:
    person(long id)
    {
        this->id = id;
    }
    bool operator == (const person& person) const
    {
        if (this->id == person.id)
            return true;
        return false;
    }
};

int main_20180715_0216()
{
    person p1(1);
    person p2(1);
    cout << "p1 == p2 ? " << (p1 == p2) << endl;
    cin.get();
    return 0;
}

 

operator

原文:https://www.cnblogs.com/heben/p/9311589.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!