我得到了这个代码:
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)