Overloading of Template Functions

Unit 4 Β· Topic 4.6⏱ 8 min read❓ 5 MCQs

Introduction

Template functions can be overloaded by providing different template or non-template versions.

Definition

Overloading Templates: multiple versions with different signatures.

C++ Code Example

template  void show(T a){ cout<

Important Questions

Short Questions

  1. What is template overloading?
  2. Can templates be overloaded?
  3. Overload resolution priority?
  4. Example?

Long Questions

  1. Explain template overloading with example.
  2. Discuss resolution.

MCQ Practice

1. Template overloading allows:

  • Multiple versions
  • Only one
  • No versions
  • None
Answer: Multiple versions.

2. Non-template overload has priority when:

  • Exact match
  • Always
  • Never
  • Sometimes
Answer: Exact match.

3. Overloading is:

  • Compile-time
  • Run-time
  • Link-time
  • Never
Answer: Compile-time.

4. Template specialization is:

  • Custom version for type
  • Overloading
  • Inheritance
  • None
Answer: Custom version for type.

5. Can partially specialize function templates?

  • No (only classes)
  • Yes
  • Always
  • None
Answer: No (only classes).

Quick Revision

  • Overload templates like functions.
  • Non-template preferred on exact match.