开发者

How do I overload an operator to work with a struct?

开发者 https://www.devze.com 2023-01-28 07:25 出处:网络
Merged with << Operator Rewrite to cout int and double values. I have a struct called Readings and I want to overload the < operator to work开发者_Python百科 with it. It\'s to co
Merged with << Operator Rewrite to cout int and double values.

I have a struct called Readings and I want to overload the < operator to work开发者_Python百科 with it. It's to compare two readings and determine which one is larger.

Here's my struct:

struct Reading {
    int hour;
    double temperature;
    Reading(int h, double t): hour(h), temperature(t) { }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消