本文介绍了C ++模板是预编译器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然不是因为人们可以通过调试器逐步执行模板代码。

但是如果我愿意在调试中做出让步,模板将是

严格来说预编译器的事情?我有一种感觉,答案我会得到

回来会不,因为模板已经过了他们自己的生活,因为

他们最初的构想现在也影响编译器实现

(读:不好,IMO。


John

Well apparently not since one can step thru template code with a debugger.
But if I was willing to make the concession on debugging, templates would be
strictly a precompiler thing? I have a feeling the answer I''m going to get
back will be "no, because templates have taken on a life of their own since
their original conception and now also affect compiler implementation"
(read: not good, IMO.

John

推荐答案



没有预编译器。


不,如果他们是,他们会受到同样的影响作为宏的缺点,

如文件范围和缺乏类型安全。


-

Ian Collins。

There isn''t a precompiler.

No, if they were, they would suffer from the same drawbacks as macros,
such as file only scope and lack of type safety.

--
Ian Collins.




没有预编译器。

There isn''t a precompiler.



好的,有,但我''我确定你不是指b $ b你想要的是什么...


-

Ian Collins。

OK, there is http://www.comeaucomputing.com/, but I''m sure that''s not
what you were referring to...

--
Ian Collins.




通过预编译器,我认为你的意思是C / C ++预处理器?

这不是*任何*类型的编译器,前置,后置或其他。

它只是一个文本编辑器。


模板是C ++语言的一部分。它们不是预处理宏的b
$ b。如果你想使用预处理器宏

(并且没有理由不这样做),请使用#define而不是template。


我,一个人,喜欢宏。和模板。我同时使用了所有的

时间。但他们甚至没有相似之处。一个是

文本编辑命令;另一个是用于构建

函数或类的系统,它可以使用泛型类型的数据。

类型需要在编译之前决定 - 是的;是的/>
但是模板删除了编写相同代码的必要性

只需处理37种不同的数据类型。


只需尝试重新对于一堆不同的数据类型来说,一个容器 - 比方说,一个二叉树 -

,你很快就会欣赏模板的价值。 (而且你会看到

宏是没有用的。)


-

干杯,

Robbie Hatley

lonewolf aatt well dott com

triple-dubya dott tustinfreezone dott org

By "precompiler", I presume you mean the C/C++ preprocessor?
That''s not *any* kind of "compiler", pre-, post-, or otherwise.
It''s just a text editor.

Templates are a part of the C++ language. They are not
preprocessor macros. If you want to use preprocessor macros
(and there''s no reason not to), use "#define", not "template".

I, for one, love macros. And templates. I use both all the
time. But they''re not even remotely similar. One is a
text-editing command; the other is a system for building
functions or classes which can use data of generic type.
The type needs to be decided-on before compile time, yes;
but templates remove the necessity of writing the same code
37 times just to handle 37 different data types.

Just try re-implimenting a container -- say, a binary tree --
for a bunch of different data types, and you''ll quickly
appreciate the value of templates. (And you''ll see that
macros are of no use for that purpose.)

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org


这篇关于C ++模板是预编译器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:39
查看更多