C++ [纠错题] int声明在函数外,怎么使用...
题目要求输出:
30
130
原题:
#include<iostream>
using namespace std;
int a = 10;
class CObj {
private:
int a, b;
public :
CObj() {
a = b = 0;
}
void display() {
cout << a << b << endl;
}
void func(int a) {
a+=a; // 纠正 this->a = a;
}
void func2() {
a +=a; // 这里我就直接改成 a+=10; 了 ,没有用到外面赋值的那个a...
}
};
int main() {
CObj obj;
obj.func(3);
obj.display();
obj.func2();
obj.display();
system("pause");
return 0;
}
#笔试题目#