#include using namespace std;class Test {static int x;public:Test() { x++; }static int getX() { return x; }~Test() {cout << x << " destroying an object\n";x--;}};int Test::x = 0;int main(){cout << Test::getX() << " ";cout << sizeof(Test) << endl;return 0;}what is the output?
查看答案
#include using namespace std;class Test {int x = 0;public:Test() { x++; }int getX() const{ return x; }};int main(){Test t0;cout << sizeof(t0) << endl;cout << t0.getX() << endl;const Test t1;cout << t1.getX() << endl;return 0;}what is the output?
#include#includeusing namespace std;class String {char* str;public:String(const char* s);void set(int index, char c) { str[index] = c; }char* get() { return str; }~String() { delete str; }};String::String(const char* s){int l = strlen(s);str = new char[l + 1];strcpy(str, s);}int main(){String s1("Quiz");s1.set(0, 'q');cout << s1.get() <
#include#includeusing namespace std;class String {char* str;public:String(const char* s);void set(int index, char c) { str[index] = c; }char* get() { return str; }~String() { cout << str <<" object is deleted \n"; delete str; }};String::String(const char* s){int l = strlen(s);str = new char[l + 1];strcpy(str, s);}int main(){String s1("Quiz");s1.set(0, 'q');cout << s1.get() <
冷凝水排人污水系统时,宜有空气隔断措施;
A. 对
B. 错