风格问题? [英] A question of style?

查看:56
本文介绍了风格问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近才开始使用VC ++学习Windows编程。

相对容易理解附加功能的基础知识

来控制但是我'一直在努力从根本上学习Windows

。在查看源代码时,我发现一些程序员倾向于使用新的
声明其应用程序类型的对象,然后使用指针成员 - 运算符访问类对象的

成员。考虑到在这些

实例中显然只有一个应用程序对象,什么

是声明指针然后经历<的过程。 br />
分配对象本身而不是简单地声明对象

并忘记分配?


-

Lilith

I''ve only recently started to learn Windows programming using VC++.
It''s relatively easy to understand the basics fo attaching functions
to controls but I''ve been trying to learn Windows from the roots on
down. In looking at source code I''m finding a tendency for some
programmers to declare an object of their application type with a new
and subsequently use the pointer-member-of operator to access the
members of the class object. Considering it was obvious in these
instances that there was only going to be one application object, what
is the point of declaring a pointer and then go through the process of
allocating the object itself rather than simply declaring the object
and forgetting the allocation?

--
Lilith

推荐答案

Lilith写道:
Lilith wrote:
我最近才开始学习Windows编程使用VC ++。


示例VC ++代码是关于您可以找到的最可怜的样式。我们这个行业中唯一更糟糕的事情是Dobb博士的期刊。

...在查看源代码时我发现了一些倾向程序员用新的
声明他们的应用程序类型的对象,然后使用pointer-member-of操作符来访问类对象的
成员。
I''ve only recently started to learn Windows programming using VC++.
Sample VC++ code is about the most wretched style you can find. The only
thing worse in our industry is Dr Dobb''s Journal.
...In looking at source code I''m finding a tendency for some
programmers to declare an object of their application type with a new
and subsequently use the pointer-member-of operator to access the
members of the class object.




你的意思是 - >符号。不是指向成员的指针。


但是,是的,这些程序员正在使用''new'',因为所有其他

程序员都在这样做,并不是因为他们需要一个物品比现在的范围更长寿




阅读像/ Design Patterns /和/ Effective C ++ /这样的书来学好风格。


-

Phlip
http://www.c2.com/cgi/wiki?ZeekLand


>我最近才开始使用VC ++学习Windows编程。
> I''ve only recently started to learn Windows programming using VC++.
将控制功能附加到控件的基础知识相对容易,但我一直在努力学习Windows从根本上下来了。


这与C ++语言无关。

在查看源代码时我发现某些程序员倾向于使用new
声明其应用程序类型的对象,然后使用pointer-member-of运算符访问类对象的
成员。考虑到在这些实例中很明显只有一个应用程序对象,是什么
是声明一个指针,然后经历分配对象本身的过程而不是而不是简单地宣布对象
并忘记分配?


我不完全确定你的问题是什么,但听起来像是你要求b $ b要求创建一个对象之间有什么区别使用new和

只是将其声明为自动变量?如果这就是你要求的那个,那么new会在堆上创建内存,声明一个自动变量

将对象放在堆栈上。另一个区别是,用一个

指针指向一个用new创建的对象,你可以使用多态。


-
Lilith
It''s relatively easy to understand the basics fo attaching functions
to controls but I''ve been trying to learn Windows from the roots on
down.
This has nothing to do with the C++ language.
In looking at source code I''m finding a tendency for some
programmers to declare an object of their application type with a new
and subsequently use the pointer-member-of operator to access the
members of the class object. Considering it was obvious in these
instances that there was only going to be one application object, what
is the point of declaring a pointer and then go through the process of
allocating the object itself rather than simply declaring the object
and forgetting the allocation?
I''m not exactly sure what your question is, but it sounds like you''re
asking "what the difference between creating an object with new and
just declaring it as an automatic variable?" If that''s what you''re
asking, new creates memory on the heap, declaring an automatic variable
puts the object on the stack. Another difference is that with a
pointer to an object created with new, you can use polymorphism.


--
Lilith






Lilith写道:
我最近才开始使用VC ++学习Windows编程。将控制功能附加到控件上的基础知识相对容易,但我一直试图从根本上学习Windows。在查看源代码时,我发现某些程序员倾向于使用新的
声明其应用程序类型的对象,然后使用指针成员运算符来访问
类对象的成员。


你的意思是 - >运算符,是吗?

考虑到在这些
实例中很明显只有一个应用程序对象,什么
是声明指针然后通过分配对象本身而不是简单地声明对象并忘记分配的过程?
I''ve only recently started to learn Windows programming using VC++.
It''s relatively easy to understand the basics fo attaching functions
to controls but I''ve been trying to learn Windows from the roots on
down. In looking at source code I''m finding a tendency for some
programmers to declare an object of their application type with a new
and subsequently use the pointer-member-of operator to access the
members of the class object.
You mean -> operator, yes?
Considering it was obvious in these
instances that there was only going to be one application object, what
is the point of declaring a pointer and then go through the process of
allocating the object itself rather than simply declaring the object
and forgetting the allocation?




区别在于对象的分配位置和_when_它是初始化的
。静态分配的对象(具有静态存储的对象

持续时间)可能分配给与具有

动态存储持续时间的对象不同的地方。此外,您可能需要在初始化应用程序对象时控制

时间。静态分配

对象在''main''函数被调用之前的某个时刻被初始化,这不一定是正确的时间。

V



The difference is where the object is allocated and _when_ it is
initialised. Statically allocated objects (objects with static storage
duration) are allocated potentially in a different place than those with
dynamic storage duration. Also, you may need to have control over the
time when your application object is initialised. Statically allocated
objects are initialised at some point before the ''main'' function is
called, which is not necessarily the right time.

V


这篇关于风格问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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