in Object Oriented Programming recategorized by
3,073 views
1 vote
1 vote

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 recategorized by
3.1k views

2 Answers

1 vote
1 vote

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.

0 votes
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.

Answer:

Related questions

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