Virtual functions, Linked list, Build error

advertisement
CSC 4111 Lab 1 Solutions to questions in part 2
1) On lines 29 to 33 of main.cpp, why is there an ‘&’ before the player variables?
A. To cast them to pointers.
2) For lines 45 to 49 of main.cpp, why not use a loop?
A. The other loops use the pointer *team, which is of type player, the base class. Since the
base class doesn’t have a setMinutes() method, it can’t be called from a pointer of the
base type.
3) On lines 10, 11 and 52 of player.h, what do the #ifndef, #define and #endif preprocessor
commands do?
A. The three preprocessor commands stop the file from being compiled multiple times.
4) On line 20 of player.h, the string name is private, what did you have to do because of this?
A. Use the base class methods to access and mutate the string name.
5) On lines 24 of player.h, why does minutes played have to be protected, not private?
A. Because the derived classes have to access it directly, to implement the pure virtual
method, setMinutes().
6) On line 43 of player.h, why is the function assigned zero?
A. To make it a pure virtual method.
7) On line 49 of player.h, what does the word ‘const’ do?
A. It makes the parameters pass to it constants.
8) What method should be entirely in the base class? Why?
A. The setMinutes() method should be in the player class; because it is the same in both of
the derived classes.
9) Which class is an abstract class? Why?
A. The player class is abstract because it has a pure virtual method, it can never be
instantiated.
10) Name one thing you learned or had forgotten and remembered in this task.
A. Hopefully you remembered everything you learned in previous classes about inheritance
and encapsulation.
Download