The Gateway to Computer Science Excellence
0 votes
Which of the following is not correct (in C++)?

1) Class templates and function templates are instantiated in the same way.

2) Class templates differ from function templates in the way they are initiated.

3) Class templates is initiated by defining an object using the template argument.

4) Class templates are generally used for storage classes.
in Object Oriented Programming by Active (4.1k points)
recategorized by | 1.1k views

1 Answer

0 votes
I think question is incomplete or incorrect as options 2,3 & 4 are not correct here. Only 1 is correct as both class templates and function templates are instantiated in the same way.

//Defines a template for a class that can hold two objects.
template<typename T1, typename T2>
struct pair {
    T1 first;
    T2 second; };
//Defines a template for a function that gives the minimum of two values.
template<typename T>
T min(T a, T b) {
    return a < b ? a : b; }

Class templates can be used to write programs that execute at compile time and here we can see template instantiations with pattern matching as pure functions.
by Active (2.1k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,291 answers
104,890 users