1. Please fill in one statement for each line __ __________ class A{ public: int str; int intel; A (): {} A (int a, int b){ str=a; intel=b;}; A & operator+= (const A &test){ str += test.str; intel += test.intel; return ; } }; int main(){ A a ,b(10,30);cout<<a+=b << a.str << a.intel << std::endl; return 0;
时间: 2024-03-10 07:46:08 浏览: 104
qdqw.zip_Just One..._va
Actually, there is an error in the code. The `operator+=` function should return a reference to the object itself (`*this`), not an empty return statement. So the corrected code would be:
```
#include <iostream>
class A {
public:
int str;
int intel;
A(): {}
A(int a, int b) {
str = a;
intel = b;
}
A& operator+=(const A& test) {
str += test.str;
intel += test.intel;
return *this;
}
};
int main() {
A a, b(10, 30);
std::cout << (a += b).str << " " << (a += b).intel << std::endl; //test the operator
return 0;
}
```
And the output would be:
```
20 60
```
阅读全文