(Find the Error) Determine whether the following program segments contain errors. For each error, explain how it can be corrected. [Note: For a particular program segment, it’s possible that no errors are present in the segment.]

a) ```
template < class A >
int sum( int num1, int num2, int num3 )
{
return num1 + num2 + num3;
}
```
b) ```
void printResults( int x, int y )
{
cout << "The sum is " << x + y << '\n';
return x + y;
}
```
c) ```
template < A >
A product( A num1, A num2, A num3 )
{
return num1 * num2 * num3;
}
```
d) ```
double cube( int );
int cube( int );
```


a) Error: The function return type and parameter types are int.
Correction: The function return type and parameter types should be A or the function should not be a template.
b) Error: The function specifies a void return type and attempts to return a value.
Two possible solutions: (1) change void to int, or (2) remove the line return x + y;.
c) Error: Keyword class is missing in the template declaration.
Correction: Insert keyword class (or keyword typename), as in template .
d) Error: The signatures are not different. Overloaded functions must have different signatures—the name and/or parameter list must be different. If only the returns types differ, the compiler generates an error message.
Correction: Change either the name or parameter list of one of the functions.

Computer Science & Information Technology

You might also like to view...

XHTML version ____ is a reformulation of HTML 4.01 in the XML language in order to provide enforceable standards for HTML content and to allow HTML to interact with other XML languages.

A. 1.0 B. 1.1 C. 2.0 D. 5.0

Computer Science & Information Technology

The number of pixels displayed on the screen is known as ________

A) brightness resolution B) screen resolution C) contrast ratio D) aspect ratio

Computer Science & Information Technology

The Children's Online Privacy Protection Act ("COPPA") applies to whom?

A. Operators of websites soliciting business in the United States B. Operators of websites soliciting financial information from customers in the United States C. Operators of commercial websites that are directed to children under 13 years of age D. Operators of commercial websites that are directed to children under 18 years of age

Computer Science & Information Technology

Google Drive is an example of a ___________ cloud.

A. Hybrid B. Private C. Public D. Vertical

Computer Science & Information Technology