The Gateway to Computer Science Excellence
+1 vote
1.1k views

Which of the following is incorrect in C++?

  1. when we write overloaded function we must code the function for each usage
  2. when we write function template we code the function only once
  3. it is difficult to debug macros
  4. templates are more efficient than macros
in Object Oriented Programming by Veteran (104k points)
recategorized by | 1.1k views

2 Answers

0 votes

ans should be none of these 

first 3 choices are correct and so is 4th

Templates undoubtedly take longer.

However, templates are significantly more powerful and obey C++ syntactical rules, whereas macros do not.

The reason Templates take longer is because you can have a template which is recursive, and all of those recurrences need to be generated. This is the foundation upon which looping constructs in Template Metaprogramming are built. Macros, in contrast, cannot call themselves, and are therefore limited to a single expansion.

by Boss (48.6k points)
0 votes

A function template by itself is not a type, or a function, or any other entity. No code is generated from a source file that contains only template definitions. In order for any code to appear, a template must be instantiated: the template arguments must be determined so that the compiler can generate an actual function (or class, from a class template).

Why do they have a bad reputation - hard to use well - most macro system are so simplistic they make it harder - difficult to debug.

Everyone knows f'n overloading.

d) just coz template takes more time.

by (445 points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,654 questions
56,169 answers
193,881 comments
94,304 users