Overloading of Template Functions
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
Important Questions
Short Questions
- What is template overloading?
- Can templates be overloaded?
- Overload resolution priority?
- Example?
Long Questions
- Explain template overloading with example.
- 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.