题目内容

When a copy constructor may be called?

A. When an object of the class is returned by value
B. When an object of the class is passed (to a function) by value as an argument
C. When an object is constructed based on another object of the same class
D. All of the above

查看答案
更多问题

An initializer list in a constructor must be used when

A. there is a reference variable in class
B. there is a constant variable in class
C. there is an object of another class. And the other class does not have default constructor
D. All of the above

#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() <

答案查题题库