Describe the syntax we use for a class template.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

Describe the syntax we use for a class template.

Expert Solution
Step 1

Class template:

A class template creates basic outline for a class. The members of that class use arguments of the type template argument. The syntax statement for class template declaration is as below:

Step 2

template <class template_name> class class_name {

class_namemember_name( template_nameargument_name)

};

Class template specialization is the instant of a function created by the compiler from the template for a specific set of arguments passed to the object. The syntax statements are specialized as in the example below:

  • Consider a class template display with type parameter class_name called with double arguments.
  • The compiler then detects a display object invocation in the code.
  • Type parameter template_name is substituted by double throughout the definition.
  • The class template specialization created is display< double> instead of template type display <template_name>.
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT