Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 258 - 258 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 258

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Differentiate between a template class and class template.

Explanation

  • Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. In other words plain templates
    • Function templates allow creating generic functions with same bodies which can take different data types as parameters.
    • In some situations classes are similar and perform very similar operations
    • Instead of creating several similar classes, programmer might consider developing a template class, a class in which at least one type is generic or parameterized.
    • Syntax of template class:

    Template < type name T > Class class1 {/ ⚹ … ⚹ /} ;

  • Class Template: A class template specifies how individual classes are constructed much like a class specifying how individual objects can be constructed. In other words, they are plain classes.
    • Like function template, a class template is a common class that can represent various similar classes operating on data of different types.
    • Once a class template is defined, programmer can create an object of that class using a specific basic or user-defined data types to replace the generic data types used during class definition.
    • Syntax of Class Template:
  1. Template <classT1, classT2 … >
  2. Classclassname
  3. {
  4.     Attributes;
  5.     Methods;
  6. };

Developed by: