正确的C ++教程第2.1章“类”可用(Windows,mingw / msvc / std) [英] Correct C++ tutorial chapter 2.1 "Classes" available (Windows, mingw/msvc/std)

查看:53
本文介绍了正确的C ++教程第2.1章“类”可用(Windows,mingw / msvc / std)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过的Correct C ++教程的第8章(第2.1章)现在已经可以使用了b $ b,虽然目前只有Word格式 - 欢迎评论!


使用免费&系统独立的开放式办公室,如果你没有Word。


课程

< url:http://home.no.net/dubjai /win32cpptut/w32cpptut_02_01.zip>


介绍用于定义新类型的C ++语言功能,即

类。重点是创建安全和可重用的类。作为主要的

主题,重新讨论了第1.4章中的jugs-puzzle程序,

章节以一个解决这个难题的示例程序结束。


一般网址:


< url:http://home.no.net/dubjai/win32cpptut/html/>

除了

所有章节的原始Word文档之外,还提供了第1.1和1.2章作为网页(HTML)。


目录,第2.1章:


1 [背景:] POD,聚合和纯C ++类。

2分类和定义一般对象成员例程。 br />
3在头文件中放置内联例程定义。

4设计无i / o类。

5调整类以支持易用性,I。

6将用户界面代码重构为一个类(类作为模块)。

7使类几乎万无一失。访问成员。

8使用构造函数负责每个实例的初始化。

9使用显式构造函数防止隐式转换。

10调整一个支持易用性的类,II。

11默认构造函数&构造函数调用保证。

12使用构造函数初始化列表初始化成员。

13在程序中使用类的完整示例。


和以前一样,邀请评论的意思是_fix_任何不正确的,或者

演示文稿,或者其他什么;你的输入很有价值,因此你可以帮助那些偶然发现本教程并用它来学习C ++的人。


提前谢谢,


- Alf


-

答:因为它弄乱了人们通常阅读文字的顺序。 />
问:为什么这么糟糕?

A:热门发布。

问:usenet上最烦人的事情是什么?电子邮件?


[见 http://www.gotw.ca/resources/clcm.htm 了解有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]

解决方案

Alf P. Steinbach写道:

[snip]

内容,第2.1章:




我认为一般的动机为什么这个世界为什么后来演变成OOP而不是函数式编程的原因背后的原因。
我看到它的整个OO动机的一个重要点(有些人

会说它只是C ++背后的动机,我会说OO)是类型安全的!

(这就是为什么C ++是最好的OO语言,尽管缺少几个很大的

OO功能......)


如果你封装了函数wag()在类DogTail中你没有b $ b不喜欢摇摇晃晃的狗(狗)!

或者用简单的英语说,如果你没有类型安全,你可以运行

尝试飞行的危险()潜水艇...


课程背后的另一个目标是我看到它的封装和

datahiding。


我可能错过了几个好点,但我的观点是

你应该先尝试激活你的读者教他们

新的东西对他们来说似乎是不合时宜的,他们先花时间在

...


我也是''首先要强调私人关键词,毕竟

如果私人数据不在课堂上,那么

上课就没有意义因为整个想法将函数和数据封装在一起,这意味着X

的每个操作都位于X内,这意味着你可以很容易地看到X' terface和

轻松发现X的所有潜在问题区域(X'的公共数据和

函数)


我'我希望有一个名为问题的标题。另一个名为

Encapsulation and private as your great friend或者什么...


毕竟,课程不是关于你能做什么的,而是关于什么

你不能做什么!!


除了那个像往常一样非常出色的工作Alf!


顺便说一句,我还在等待一个关于我是否能镜像的答案您在SmartWin网站上的
教程...


Thomas Hansen

[见 http://www.gotw.ca/resources/clcm.htm 有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]


* Thomas Hansen:

Alf P. Steinbach写道:
[snip]

目录,第2.1章:
我认为一般的动机为什么世界变成OOP而不是函数式编程的原因背后缺乏。




所有的时间......; - )

在本章中我只强调了C ++如何具有语言功能

直接解决遇到的问题,解决的问题不那么优雅,而且安全性低于
前几章。


这是开始使用课程的个人动机;为什么

世界这样做,总结,(0)Vannevar Bush,我希望他与GW没有关系,以及他的技术见解,( 1)模拟,Simula,

Norsk Regnesentral / Oslo University 1960年代后期, - > (2)Alan Kay,尝试使用
来理解实际上是Simula的Algol编译器,以及

已经了解了Bush的想法, - > (3)Xerox Palo Alto的Smalltalk GUI +语言+ OS +

计算机+网络+可用性+教学思想项目

研究中心(Xerox PARC)1970年代中期到了1980年代早期, - > (4)

Bjarne Stroustrup进行模拟,几乎所有其他人都延伸

C with OO ideas,1980年,(5)Apple Lisa,Apple的成果

受邀评估Smalltalk,并没有像惠普一样愚蠢,或者它是不是很好.... / b
Tektronix(试图基于矢量图形终端制作GUI),(6)

Apple Macintosh,一种Lisa Light,(7)X11和MS Windows,在1980年代后期中间到
,我不得不问,无论什么变成出租车和所有其他图形用户界面

用于PC',而不要忘记,Niklaus Wirth'的Oberon机器Lilith?

[snip]
顺便说一下,我还在等待一个答案,我是否可以在SmartWin网站上反映你的
教程......




我不是知道你会问。但无论如何。 _如果你在它上面写了一个日期

(复制时),对原文的引用,以及

副本可能不是最新更新的效果的措辞。只需

提供链接就更简单了。这样,该网站甚至可能会列在谷歌! :-)


-

答:因为它弄乱了人们通常阅读文本的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的是什么?


[见 http://www.gotw。 ca / resources / clcm.htm 有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]


Thomas Hansen写道:

Alf P. Steinbach写道:
[snip]
< blockquote class =post_quotes>内容,第2.1章:



我认为一般的动机为什么世界变成OOP而不是函数式编程的原因背后缺乏。
我看到它的整个OO动机的一个重点(有些人会说''只有C ++背后的动机,我会说OO)是类型安全的!
(这就是为什么C ++是最好的OO语言,尽管缺少几个大的OO功能......)




我可能会在这里误解你的评论,但是输入安全性很少

与OO有关 - 它只与静态类型的UP语言相关。

存在动态类型语言,也是OOPL。


剪掉剩余的......

Andrew


[见 http://www.gotw.ca/ resources / clcm.htm 有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]


The eighth chapter (chapter 2.1) of my attempted Correct C++ tutorial is now
available, although for now only in Word format -- comments welcome!

Use the free & system-independent Open Office if you don''t have Word.

Classes
<url: http://home.no.net/dubjai/win32cpptut/w32cpptut_02_01.zip>

Introduces the C++ language feature used to define new types, namely
classes. The focus in on creating safe and reusable classes. As a main
theme the jugs-puzzle program from chapter 1.4 is revisited, and the
chapter ends with an example program that solves the puzzle.

General URL:

<url: http://home.no.net/dubjai/win32cpptut/html/>

which provides chapters 1.1 and 1.2 as web-pages (HTML) in addition to the
original Word documents of all chapters in zipped format.

Contents, chapter 2.1:

1 [Background:] PODs, aggregates and pure C++ classes.
2 Classify and define general object member routines.
3 Place inline routine definitions in header files.
4 Design i/o-free classes.
5 Adjust a class to support ease of use, I.
6 Refactor user interface code as a class (class as module).
7 Make a class almost foolproof wrt. access to members.
8 Take charge of per-instance initialization with constructors.
9 Prevent implicit conversions by using explicit constructors.
10 Adjust a class to support ease of use, II.
11 Default constructors & the constructor call guarantee.
12 Use constructor initializer lists to initialize members.
13 A complete example of using classes in a program.

As before, the point of inviting comments is to _fix_ anything incorrect, or
the presentation, or whatever; your input is valuable, and you can thereby
help those who stumble across this tutorial and use it to learn C++.

Thanks in advance,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

解决方案

Alf P. Steinbach wrote:
[snip]

Contents, chapter 2.1:



I think a general "motivation" behind the REASONS to WHY the world
evolved into OOP instead of functional programming is lacking.
A big point in the whole OO motivation the way I see it (some people
will say it''s a motivation behind only C++, I''d say OO) is typesafety!
(That''s why C++ is THE best OO language even though lacking several big
OO features...)

If you encapsulate the function "wag()" in the class "DogTail" you
don''t run the risc of of wagging() the Dog!
Or said in plain English, if you don''t have typesafety you can run the
risc of trying to fly() a Submarine...

Another objective behind classes the way I see it is encapsulation and
datahiding.

Might be I''ve missed out several good points here, but my point is that
you should first MOTIVATE your readers before trying to teach them
something new which will seem unnessecary for them to spend time on at
first...

Also I''d stress the private keyword to a much bigger extend, after all
if the private data wasn''t around in classes there would be no point in
having classes since the whole idea is encapsulating the functions
together with the data meaning that every operation possible for X
resides inside X which means you can easily see the X''s interface and
easily spot all potential problem areas of X (X''s public data and
functions)

I''d like to have a header called "The problem" and another called
"Encapsulation and private as your biggest friend" or something...

After all, classes are not about what you CAN do, they''re about what
you CAN NOT do!!

Apart from that as usual off course excellent work Alf!

Btw, I''m still waiting for an answer regarding if I can mirror your
tutorials on the SmartWin website...

Thomas Hansen
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


* Thomas Hansen:

Alf P. Steinbach wrote:
[snip]

Contents, chapter 2.1:
I think a general "motivation" behind the REASONS to WHY the world
evolved into OOP instead of functional programming is lacking.



All in good time... ;-)

For this chapter I just stressed how C++ has language features that
directly solve the problems encountered and solved less elegantly and less
safely in earlier chapters.

That''s sort of personal motivation to start using classes; why the
world at large did so is, summary, (0) Vannevar Bush, I hope he''s not
a relation to GW, and his technological insights, (1) simulations, Simula,
Norsk Regnesentral / Oslo University late 1960''s, -> (2) Alan Kay, trying
to make sense of an Algol compiler that was actually Simula, and also
having picked up the ideas of Bush, -> (3) the Smalltalk GUI + language + OS +
computer + network + usability + pedagogical ideas project at Xerox Palo Alto
Research Center (Xerox PARC) in the middle 1970''s to early 1980''s, -> (4)
Bjarne Stroustrup doing simulations and as just about everyone else extending
C with OO ideas, cirka 1980, (5) the Apple Lisa, the fruits of Apple being
invited to evaluate Smalltalk, and not being as silly as HP or was it
Tektronix (who tried to make a GUI based on a vector graphics terminal), (6)
the Apple Macintosh, a kind of Lisa Light, (7) X11 and MS Windows, middle to
late 1980''s, and I have to ask, whatever became of Taxi and all the other GUIs
for PC''s, and not to forget, Niklaus Wirth''s Oberon machine Lilith?
[snip]
Btw, I''m still waiting for an answer regarding if I can mirror your
tutorials on the SmartWin website...



I wasn''t aware you''d asked. But by all means. _If_ you put a date on it
(when copied), a reference to the original, and wording to the effect that
the copy may not be the latest update. It is of course simpler to just
provide links. That way the site may even be listed in Google! :-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Thomas Hansen wrote:

Alf P. Steinbach wrote:
[snip]

Contents, chapter 2.1:


I think a general "motivation" behind the REASONS to WHY the world
evolved into OOP instead of functional programming is lacking.
A big point in the whole OO motivation the way I see it (some people
will say it''s a motivation behind only C++, I''d say OO) is typesafety!
(That''s why C++ is THE best OO language even though lacking several big
OO features...)



I might be mis-interpreting your comments here, but type safety little
to do with OO - its only relevant in UP Languages that are static typed.
Dynamic typed languages exist and are also OOPLs.

snipped remaining...
Andrew

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


这篇关于正确的C ++教程第2.1章“类”可用(Windows,mingw / msvc / std)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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