Behold the declaration of the MyClass class below. Please answer the following true/false questions:
1
2
3
4
5
6
7
8
9
10
11
12
13
/* 1 */ class MyClass {
/* 2 */ public:
/* 3 */ MyClass();
/* 4 */ MyClass *Copy();
/* 5 */ MyClass(const MyClass &mc);
/* 6 */ void A(Otherclass &s) const;
/* 7 */ void B(Otherclass &s);
/* 8 */ void C(Otherclass &s) const;
/* 9 */ void D(const Otherclass &s);
/* 10 */ int F;
/* 11 */ protected:
/* 12 */ vector <int> v;
/* 13 */ };
A. The copy constructor is declared on line 3.
B. The copy constructor is declared on line 4.
C. The copy constructor is declared on line 5.
D. The method A() cannot change change s.
E. The method B() cannot change change s.
F. The method C() cannot change change s.
G. The method D() cannot change change s.
H. The method A() cannot change change v.
I. The method B() cannot change change v.
J. The method C() cannot change change v.
K. The method D() cannot change change v.
L. When you call A(), you will call Otherclass’ copy constructor.
M. When you call B(), you will call Otherclass’ copy constructor.
N. When you call A(), you will call Otherclass’ regular constructor.
O. When you call B(), you will call Otherclass’ regular constructor.
P. When A() returns, it will call the destructor for s.
Q. When B() returns, it will call the destructor for s.
R. This header won’t compile, because F should be protected.
S. If x and y are declared as MyClass variables, I’m allowed to say “x=y, even though I didn’t declare an assignment overload.
T. There is a memory leak, because there is no destructor to free up the memory corresponding to the variable v.
U. If Copy() calls new, I should have a destructor that calls delete.
No Class Stats, PDF Download