Which of the following statements about the member function is correct?
A member function defined outside of the class where it is declared does not have class scope
B. Member functions cannot be overloaded
C. Member functions can be modified when the const keyword is placed after the parameter list in the function declaration
D. Static member functions do not need any object to be invoked
查看答案
#include using namespace std;class Test{public:static int i;static int get();Test() { i++; }};int Test::i = 0;int Test::get(){return i;}Test t;int main(){Test t;cout<
#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() <