Practice 1int &getRefData() int *getPointerData() The return value of the above two function can be the "left hand side" of a substitution statement. Hence the member variable data can be changed without usingadd|subValue() functions. Although data was declared as a private variable, these two function exposed it, hence breaking the effect of encapsulation. You can change them as: const int &getRefData() const{ return data; } const int *getPointerData() const { return &data; } Practice 2The problem is to have two delete statements in the loop. For the 2nd loop, pp1 and p2 are already deleted. for (int...) { ... } delete pp1, pp1 = NULL; delete pp2, pp2 = NULL; You should also substitute NULL to the variable, which should be released. Practice 3
|