n*****r 发帖数: 159 | 1 Templates are often thought to be very similar to C-style macros. Which
one of the following statements about templates is true?
Choice 1 Macros have static linkage; templates have external linkage.
Choice 2 Templates are strongly typed; macros are not.
Choice 3 Macros are evaluated at compile time; templates are at runtime.
Choice 4 Class templates are less efficient than class macros.
Choice 5 You can inherit from a macro.
I know 1,3 is not correct. How about 2,4,5? | p*u 发帖数: 2454 | 2 i think 1 and 2 are correct, unless it's a template function with internal l
inkage.
4 is vague, define "efficient" first.
【在 n*****r 的大作中提到】 : Templates are often thought to be very similar to C-style macros. Which : one of the following statements about templates is true? : Choice 1 Macros have static linkage; templates have external linkage. : Choice 2 Templates are strongly typed; macros are not. : Choice 3 Macros are evaluated at compile time; templates are at runtime. : Choice 4 Class templates are less efficient than class macros. : Choice 5 You can inherit from a macro. : I know 1,3 is not correct. How about 2,4,5?
| k****f 发帖数: 3794 | 3 第一个是什么意思?静态链接?
l
【在 p*u 的大作中提到】 : i think 1 and 2 are correct, unless it's a template function with internal l : inkage. : 4 is vague, define "efficient" first.
| n*****r 发帖数: 159 | 4 I searched c++ standard and found no definition of static linkage, so choice
1 may not be correct. For choice 4, if efficient means run-time cost (
calling overhead, storage, et al.),
Is it correct?
l
【在 p*u 的大作中提到】 : i think 1 and 2 are correct, unless it's a template function with internal l : inkage. : 4 is vague, define "efficient" first.
| p*u 发帖数: 2454 | 5
choice
~~~~~~~~~~~~~~~~~~what's ur logic here?
I don't think it's correct.
【在 n*****r 的大作中提到】 : I searched c++ standard and found no definition of static linkage, so choice : 1 may not be correct. For choice 4, if efficient means run-time cost ( : calling overhead, storage, et al.), : Is it correct? : : l
| N*********y 发帖数: 105 | 6 Agree, 4 should not be correct. For 1, is macro static linkage if static
linkage is what we understand?
【在 p*u 的大作中提到】 : : choice : ~~~~~~~~~~~~~~~~~~what's ur logic here? : I don't think it's correct.
| t****t 发帖数: 6806 | 7 there is no "static linkage". there's only 3 types of linkage: external,
internal and no linkage. external linkage object can be referred in other
translation units, internal linkage can be referred in the same translation
unit but in different scope, no linkage can't be referred outside the scope.
whatever static linkage is, both template and macro can be external or
internal linkage. mixing macro and linkage are vague and not strict anyway,
since macros are not seen by compilers at all.
【在 N*********y 的大作中提到】 : Agree, 4 should not be correct. For 1, is macro static linkage if static : linkage is what we understand?
| N*********y 发帖数: 105 | 8 mostly I agree with you. I would assume static linkage is meant to be
internal linkage here, considering the meaning of "static" keywords.
translation
scope.
,
【在 t****t 的大作中提到】 : there is no "static linkage". there's only 3 types of linkage: external, : internal and no linkage. external linkage object can be referred in other : translation units, internal linkage can be referred in the same translation : unit but in different scope, no linkage can't be referred outside the scope. : whatever static linkage is, both template and macro can be external or : internal linkage. mixing macro and linkage are vague and not strict anyway, : since macros are not seen by compilers at all.
| w**s 发帖数: 1911 | |
|