定义一个计数器类counter,包含私有成员int n ,重载运算符“+”,实现对象的相加
时间: 2024-05-30 21:16:24 浏览: 73
django中实现一个高性能计数器(counter)实例.docx
class Counter {
private:
int n;
public:
Counter(int num = 0) {
n = num;
}
Counter operator+(const Counter& c) {
Counter result;
result.n = n + c.n;
return result;
}
};
阅读全文