GCO4020/CSC428 - Advanced Object Oriented Techniques In C++
Week 4
auto_ptr class also provides features which reduce the chance
that two or more auto_ptr's will end up pointing to the same piece
of memory. Describe those features and how auto_ptr implements
them.
RefCount::Ptr() does nothing but
provide unrestricted access to the pointer (myPtr) being guarded
by a RefCount object, suggest a reason why myPtr
shouldn't just be made public and accessed directly?
There is a sample solution for Exercise 2.
RefCount::Clone() member function, for
RefCount<char> solves the problem of cloning
reference-counted char* strings, but is
insufficient in the general case. Explain why.
There is a sample solution for Exercise 3.
RefCountedPointerTo could be used
to circumvent the reference counting mechanism.
Explain how this might occur and what the consequences
might be.
There is a sample solution for Exercise 4.
RefCount::Incr() as a const member function
implies that a const RefCount should never be declared, since an
Incr() on it would be permitted by the compiler but would result
in undefined behaviour. Explain why it is reasonable to assume that
a const RefCount will never be required in a program.
There is a sample solution for Exercise 5.
RefCountedPtrTo::operator=
is not simply an optimization
for efficiency (although it does have that effect). Explain why the
check is essential to the correct behaviour of the assignment
operation.
There is a sample solution for Exercise 6.
head
pointer is destroyed.
Last updated: Fri Feb 18 11:17:28 2000