小编Ida*_*yev的帖子

C++:需要帮助理解运算符重载错误

我得到了这个代码:

1 #include <iostream>
2 using namespace std;
3
4 class B {
5 private:
6      int n;
7 public:
8      B(int x) : n(x) {}
9      B operator +(B& b) {
10         return B(n+b.n);
11     }
12     friend ostream& operator <<(ostream &out, const B& b) {
13         out << "B: " << b.n;
14         return out;
15     }
16     bool operator <(const B& rhs) const{
17         return n < rhs.n;
18     }
19 };
20
21 B smaller (const …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading operators c++11

3
推荐指数
1
解决办法
62
查看次数

标签 统计

c++ ×1

c++11 ×1

operator-overloading ×1

operators ×1