recategorized by
3,186 views
1 votes
1 votes

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
recategorized by

2 Answers

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

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

2 votes
2 votes
1 answer
1
go_editor asked Jul 30, 2016
7,419 views
When the inheritance is private, the private methods in base class are _____ in the derived class (in C++)inaccessible accessibleprotectedpublic
2 votes
2 votes
3 answers
2
go_editor asked Jul 30, 2016
6,742 views
Which of the following, in C++, is inherited in a derived class from base class?constructordestructordata membersvirtual methods