Answer the following statements true (T) or false (F)
1. Virtual functions allow old code to call new code.
2. Virtual functions are implemented with a table look up that is done at run time.
3. Late binding refers to a failure to secure one’s ski boots.
4. In a class, functions declared with the virtual keyword need not be defined.
5. he virtual function mechanism binds the “right” function to objects.
1. True
: Suppose the base class (already defined) called Figure. Figure has a draw member function declared with the virtual keyword and a member center. The center function, to do its job, calls erase, then calls draw to center the figure. In this case, a programmer can derive a class Triangle from the already defined (old) code for Figure. The derived class can have a different implementation (new code) of the virtual function draw, which will be called by the center member function. Thus old code calls new code.
2. True
When you label a function virtual, that tells the compiler, “Remember this label. Put information about all the functions labeled virtual in a table so you can decide at run-time which version one to use.”
3. False
Late binding refers to the fact that the decision as to which virtual function member in an inheritance hierarchy is called may be made during program execution rather than at compile time.
4. False
There is a table set up by C++ that needs to know where the function definition is located. If you did not supply one, there will be an error message and the compilation will abort. The error message may not be particularly clear. My compiler complains about ‘missing virtual table’. Non-virtual functions can always be declared but no defined, unless you call them, that is). There is an exception to this: pure virtual functions, in which the body of the function is replaced by =0.
5. True
The mechanism is to build a table that is filled in partly at compile time and partly at runtime, then it is read at runtime to decide which function to call.
You might also like to view...
In most programming languages, the subscript of the last character of a string would be one less than the string's __________.
Fill in the blank(s) with the appropriate word(s).
Create a file named answer and give the following command:
$ > answers.0102 < answer cat Explain what the command does and why. What is a more conventional way of expressing this command?
Given the following code snippet, what will be displayed on the web page if the user enters 5Guys! at the prompt?
``` var result = " "; var guys = prompt("How many guys are there?"); result = (parseInt(guys); document.write(result); ``` a. 5Guys! b. 5.0 c. NaN d. 5
The Facebook ________ is a strip of buttons or commands located at the top of every Facebook page
Fill in the blank(s) with correct word