码迷,mamicode.com
首页 > 其他好文 > 详细

简单的class及运算符重载

时间:2019-03-16 16:54:16      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:opera   tor   main   include   public   const   cti   space   begin   

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


class Action
{
    public:
    int room;
    int time;
    int type;

    Action(int room_, int time_, int type_)
    {
        room = room_;
        time = time_;
        type = type_;
    };
    show()
    {
    cout<<"the message is "<<room<<" "<<time<<" "<<type<<endl;
    return 0;
    };

    bool operator< (const Action &other) const {
        if(time<other.time) return true;
        else if(time==other.time && type<other.type) return true;
        else if(time==other.time && type==other.type && room<other.room) return true;
        return false;
        }

};

int main()
{
    Action t1(1,22,3);
    Action t2(1,4,3);

    vector<Action> action;

    action.push_back(t1);
    action.push_back(t2);

    sort(action.begin(), action.end());
//  for (int i =0 ; i< action.size(); i++)
//      action[i].show();
    return 0;
}

简单的class及运算符重载

标签:opera   tor   main   include   public   const   cti   space   begin   

原文地址:https://www.cnblogs.com/yeran/p/10542889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!