3i Infotech Papers: Sample Questions 657 - 657 of 1245

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 657

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

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 < class T1class T2 … >
  2. Class class name
  3. {
  4.     Attributes;
  5.     Methods;
  6. };