C ++模板教程/评论:评论欢迎 [英] C++ template tutorial/review : comments welcomed

查看:73
本文介绍了C ++模板教程/评论:评论欢迎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:


我注意到这里经常有人询问模板

所以我想可以在这里发布这条消息。我刚刚写了一篇c ++

tempalte教程/评论,我想听听其他用户的反馈。我自己对模板没有多少经验,所以我确信这个材料​​有很多问题甚至是错误。欢迎所有类型的评论

。我也希望本教程/评论对程序员有用

想要了解模板。


以下是html版本的链接:

http://www.cs.indiana .edu /~gluan / cpp ... e_tutorial.htm


谢谢,

国涛

Hello All:

I notice that there have been frequent questions being asked about template
here so I guess it is okay to post this message here. I just wrote a c++
tempalte tutorial/review, I would like to hear feedbacks from other users. I
do not have much experience with template myself so I am sure there are many
problems or even mistakes in this material. Comments of all types are
welcomed. and I also hope this tutorial/review is helpful for programmers
who want to learn about template.

Here is the link to the html version:

http://www.cs.indiana.edu/~gluan/cpp...e_tutorial.htm

Thanks,
Guotao

推荐答案

郭涛栾写道:
我注意到这里有关于模板的常见问题
所以我想发布这条消息是可以的这里。我刚刚写了一篇c ++
tempalte教程/评论,我想听听其他用户的反馈。我自己对模板没有多少经验,所以我确信这个材料​​有很多问题甚至是错误。欢迎所有类型的评论。我也希望本教程/评论对于想要学习模板的程序员有用。

以下是html版本的链接:

http://www.cs.indiana.edu/~gluan/cpp。 ..e_tutorial.htm
I notice that there have been frequent questions being asked about template
here so I guess it is okay to post this message here. I just wrote a c++
tempalte tutorial/review, I would like to hear feedbacks from other users. I
do not have much experience with template myself so I am sure there are many
problems or even mistakes in this material. Comments of all types are
welcomed. and I also hope this tutorial/review is helpful for programmers
who want to learn about template.

Here is the link to the html version:

http://www.cs.indiana.edu/~gluan/cpp...e_tutorial.htm




从第一分钟开始看几件事:


(a)引入错误的编程技术并不是使用其他语言结构来证明其合理性的好方法。没有人在他们的右边

介意会省略内括号


#define mySquare(x)(x * x)


他们会写


#define mySquare(x)((x)*(x))


虽然它没有要解决一些其他问题,肯定会把b / b
阻止mySquare(3 + 4)评估到22(而不是你写的19)。


(b)请用标准main替​​换_tmain废话并删除TCHAR(除非你在每个例子中都包含它的定义)

教授编译器特定的东西通用语言课程

一个不好的想法(tm)。


我不打算对你的教程做更多的评论。这两件事已经让我感觉很糟糕了。


想要了解模板的程序员应该阅读有关
$ b的书籍$ b模板。有几个。你提到NONE。这是为什么?你听说过The C ++模板吗? Vandevoorde和Josuttis?什么

关于加速C ++,只是为了踢?和C ++标准库?

你甚至都没有提到The C ++ Programming Language。作者:Stroustrup。

为什么不呢?


不,你的教程绝对不是我建议任何人去的地方

去学习模板。不管怎么说。


祝你好运!


V



Couple of things from the very first minute of looking it over:

(a) Introduction of bad programming techniques is not a good way to
justify using other language constructs. Nobody in their right
mind would omit inner parentheses in

#define mySquare(x) (x * x)

They would write

#define mySquare(x) ((x) * (x))

and while it doesn''t solve some other problems, it would definitely
prevent mySquare(3+4) from evaluating to 22 (and not 19 as you wrote).

(b) Please replace the _tmain nonsense with the standard main and drop
the TCHAR (unless you include the definition of it in every example)
Teaching compiler-specific things in a generic language course is
A BAD IDEA(tm).

I am not going to comment more on your tutorial. These two things have
already left a bad taste in my mouth.

Programmers who want to learn about templates should read books about
templates. There are several. You mention NONE. Why is that? Have
you heard of "The C++ Templates" by Vandevoorde and Josuttis? What
about "Accelerated C++", just for kicks? And "The C++ Standard Library"?
You don''t even mention "The C++ Programming Language" by Stroustrup.
WHY NOT?

No, your tutorial definitely not the place where I''d advise anybody to
go to learn about templates. Not yet, anyway.

Good luck fixing it!

V


国涛栾发布:
Guotao Luan posted:
大家好:

我注意到这里有关于
模板的常见问题,所以我想这没关系在这里发布此消息。我只是写了一篇c ++ tempalte教程/评论,我想听听其他用户的反馈意见。我自己对模板没有多少经验所以
我相信这些材料有很多问题甚至是错误。
各种类型的评论都很受欢迎。我也希望这个
教程/评论对想要了解
模板的程序员有所帮助。

以下是html版本的链接:

http://www.cs.indiana.edu/~ gluan / cpp ... e_tutorial.htm

谢谢,
国涛
Hello All:

I notice that there have been frequent questions being asked about
template here so I guess it is okay to post this message here. I just
wrote a c++ tempalte tutorial/review, I would like to hear feedbacks
from other users. I do not have much experience with template myself so
I am sure there are many problems or even mistakes in this material.
Comments of all types are welcomed. and I also hope this
tutorial/review is helpful for programmers who want to learn about
template.

Here is the link to the html version:

http://www.cs.indiana.edu/~gluan/cpp...e_tutorial.htm

Thanks,
Guotao




Bjarne会在这里发帖吗?


-JKop



Does Bjarne ever post here?

-JKop


郭涛栾写道:
大家好:

我注意到这里有关于
模板的常见问题,所以我想在这里发布此消息是可以的。我只是写了一篇c ++ tempalte教程/评论,我想听听其他用户的反馈意见。我自己对模板没有多少经验
所以我确信这个
材料有很多问题甚至错误。欢迎所有类型的评论。我也希望这个
教程/评论对想要了解
模板的程序员有所帮助。

以下是html版本的链接:

http://www.cs.indiana.edu/~ gluan / cpp ... e_tutorial.htm




我没有时间阅读如此广泛的文章,但我瞥了一眼

你的第一章并且必须不同意以下内容:你说语言

如C#和Java不处理模板因为它们有统一的

对象模型,其对象派生自一个基类。这不是真的,

本身。我不能说Java(我的经验并不够大),但是.Net中的
至少还有一些使用广义的缺点

使用System.Object而不是模板的集合类。大的

缺点是:

1.繁琐的代码:对System.Object的强制转换是隐式的,但是从

System.Object强制转换为你想要的类型是不是(至少不是在C#中,如果打开Option Strict,也不是VB.NET中的
)。如果你将多种类型的对象放入一个容器中,你需要使用更加繁琐的代码来跟踪它们是什么类型的b $ b。如果您不确定

容器中的对象类型,由于添加了类型检查和转换的代码,简单的foreach迭代变得非常复杂。

2.性能:Casting会受到性能影响。在VB.NET中,你可以通过使用DirectCast来最小化

,但这并不总是有效。使用值类型

(从System.ValueType继承的对象,如Int32(int),Boolean

(bool),DateTime以及所有结构和枚举,命中更大,因为

这些需要装箱和拆箱才能放入一个通用的容器中。

3.类型安全:如果你想要一个容器,就无法确保

只是某种类型,它实际上只包含那种类型。


因此,.Net已经提供了一些现成的专门收藏品

在System.Collections.Specialized命名空间中。不仅如此,而且泛型

将被添加到代号为Whidbey(.Net 2.0),尽管它在一个完全不同的方式(语法与实现方式不同)


查看以下文章:

..NET:介绍泛型在CLR中
http:// msdn。 microsoft.com/msdnmag/is起诉/ 03/09 / NET /

..NET:关于CLR中泛型的更多信息
http://msdn.microsoft.com/msdnmag/is...T/default.aspx


-

不可原谅



I don''t have the time to read such an extensive piece, but I glanced over
your first chapter and must disagree with the following: you say languages
such as C# and Java don''t deal with templates because they have a unified
object model with object that derive from one base class. This isn''t true,
per se. I can''t speak for Java (my experience with it isn''t big enough), but
in .Net at least there are still several drawbacks to using generalised
collection classes with System.Object instead of templates. The big
disadvantages are:
1. Cumbersome code: Casts to System.Object are implicit, but casts back from
System.Object to the type you desire isn''t (at least not in C#, and also not
in VB.NET if Option Strict is turned on). If you''re putting objects of
multiple types into a container, you need to keep track of what type they
are, using even more cumbersome code. Simple foreach iterations become
incredibly complex if you''re not sure of the type of objects in the
container, due to added code for type checking and casting.
2. Performance: Casting takes a performance hit. In VB.NET, you can minimize
this by using DirectCast, but that doesn''t always work. With Value Types
(objects that inherit from System.ValueType such as Int32 (int), Boolean
(bool), DateTime and all structs and enums the hit is even bigger, because
these need to be boxed and unboxed to be put in a generalised container.
3. Type safety: there is no way to ensure that if you want a container of
just a certain type, that it will in fact contain just that type.

For this reason, .Net already offers some ready-made specialised collections
in the System.Collections.Specialized namespace. Not only that, but generics
will be added to codename Whidbey (.Net 2.0), albeit in a wildly different
way from C++ (not so much in syntax as in implementation)

Check out these articles:
..NET: Introducing generics in the CLR
http://msdn.microsoft.com/msdnmag/issues/03/09/NET/
..NET: More on generics in the CLR
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

--
Unforgiven


这篇关于C ++模板教程/评论:评论欢迎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆