Question: 8. The following function accepts ints and returns an int. Write a function template (to the right) to allow this function to accept and return
8. The following function accepts ints and returns an int. Write a function template (to the right) to allow this function to accept and return other data types as well (should be 4 lines of code maximum). The same type should be used for both parameters and for the return type. int add(int x, int y) return x+ys 9. Suppose you have a template named myFunc that takes a single parame another template myFunc that takes two para compile your code? and meters, what will happen when you try to a. It will compile fine b. You will get an error, but only if both templates use the same type c. You will get an error because the compiler cannot determine which to call d. None of the above 10. Class templates are often useful if a. Your class is polymorphic because they ensure virtual function resolution b. Your class is a container class that holds a collection of objects c. Your class contains at least one function template d. None of the above 1. Which of the following is true? a. Class templates must be declared before non-template classes b. Class template implementations are typically in the header file c. Class templates can inherit from other class templates or regula d. (a) and (b) e. (b) and (c) I of the above
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
