题目内容

#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(){Test t[5];cout << Test::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::String(const char* s){int l = strlen(s);str = new char[l + 1];strcpy(str, s);}int main(){String s1("Quiz");String s2 = s1;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");String s2 = s1;s1.set(0, 'q');cout << s1.get() <

#include using namespace std;class A{public:A(){ cout <<"The A object is created\n"; }~A(){ cout << "The A object is destroyed\n"; }};class B{public:B(){ cout << "The B object is created\n"; }~B(){ cout << "The B object is destroyed\n"; }private:A a;};int main(){B b;return 0;}what is the output?

Given the declaration of the A class.class A{public:void print();private:char* p; //allocate a space in free store};1. How do you define a constructor to initialize data member p?2. If there is a statement A a = A() in the test program, whether do you need to define a copy constructor of the A class? How to define a copy constructor?

答案查题题库