LearnFrenzy
Sign in Take a free test

Templates · Templates MCQ · Question 14

Why are templates defined in header files? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 14 Back to Exercise

Why are template definitions normally placed in header files?

  • A Headers compile faster
  • B The compiler needs the full definition wherever the template is instantiated Correct
  • C Templates cannot be in .cpp files at all
  • D For security
Correct Answer: Option B

Otherwise other files see only a declaration and the linker cannot find the instantiation.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links