析构函数的可能范围 [英] Possible scopes of a destructor
问题描述
大家好,
$ c $ b我的c ++考试我回答说destructors可能被宣布为私有,
公共或受保护。
这个问题是:
析构函数有哪些可能的范围(公共或私人)?
我得到0这个答案,他们纠正我析构函数只能是
public。
当我用私有析构函数和朋友函数显示代码时
创建/销毁对象他们告诉我,我没有正确使用它,
我不称之为析构函数等....
所以,什么析构函数可能包含的范围是什么?
thans
" __ PPS __" < I - ********* @ yandex.ru>在消息中写道
news:11 ********************* @ g44g2000cwa.googlegro ups.com ...大家好,
在我的c ++考试中我回答说,析构函数可能被宣告为私有,公开或受保护。
问题是:可能的范围(公共或私人)
析构函数可以吗?
我得到了0这个答案,他们纠正了我,析构函数只能是公开的。
你是对的,他们错了。但我建议不要使用
而不是'公共',除非你真的真的知道
你在做什么,并且非常好原因。
当我用私人析构函数和朋友函数显示代码创建/销毁对象时,他们告诉我我没有正确使用它,
如果没有看到代码,我就不能发表评论。
我不称之为析构函数等....
所以,析构函数可能具有哪些范围?
上面列举的那些。
-Mike
文章< 11 ********************* @ g44g2000cwa.googlegroups。 com>,
__PPS__< i - ********* @ yandex.ru>写道:大家好,
在我的c ++考试中我回答说,析构函数可能被宣告为私有,
公开或受保护。
问题是:什么可能的范围(公共或私人)可以使用
析构函数吗?
我得到0这个答案,他们纠正了我,析构函数只能公开。
当我用私有析构函数和朋友函数显示代码创建/销毁对象时,他们告诉我我没有正确使用它,
我不称之为析构函数等等....
那么,析构函数可能具有哪些范围?
因为问题是关于* scope *正确答案
是课程范围。
然而,听起来你的问题是关于辅助功能,
即*访问*。在这种情况下,通常你不希望它,但是确保dtor可以是私人的。当然,没有正确使用东西的情况并不总是与可能的情况相同。
如果你想在这里批评你的私人代码,感觉
免费发布,与此同时,给你
考试的人显然使用了错误的术语。
-
Greg Comeau /庆祝20年的Comeauity!
Comeau C / C ++ ONLINE ==> http://www.comeaucomputing.com/tryitout
世界级编译器:令人惊叹的C ++,惊人的C99,很棒的C90。
Comeau C / C ++与Dinkumware的库...你试过吗?
" Mike Wahler" < MK ****** @ mkwahler.net>在消息中写道
新闻:Hh ************** @ newsread2.news.pas.earthlink .net ...
__ PPS __ < I - ********* @ yandex.ru>在消息中写道
新闻:11 ********************* @ g44g2000cwa.googlegro ups.com ...你好大家好,在我的c ++考试中我回答说,破坏者可能被宣布为私有,公开或受保护。
问题是:有什么可能的范围(公共或私人)可以析取器有吗?"
我得到0这个答案,他们纠正了我,析构函数只能是公开的。
你' 对了,他们错了。
但格雷格比我们任何一个人都更正确。 :-)
我忽略了滥用术语
他注意到了。
-Mike
Hello everybody,
in my exam in c++ I answered that destructors may be declared private,
public or protected.
The question was: "What possible scopes (public or private) can a
destructor have?"
I got 0 for this answer, they corrected me that destructor can only be
public.
When I showed the code with private destructor and friend functions
that create/destroy object they told me that I don''t use it correctly,
that I don''t call destructor etc etc....
So, what are the possible scopes destructors may have?
thans
"__PPS__" <i-*********@yandex.ru> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...Hello everybody,
in my exam in c++ I answered that destructors may be declared private,
public or protected.
The question was: "What possible scopes (public or private) can a
destructor have?"
I got 0 for this answer, they corrected me that destructor can only be
public.
You''re right, they''re wrong. But I''d advise against using
other than a ''public'' one unless You Really Really Know
What You''re Doing, and have a very good reason.
When I showed the code with private destructor and friend functions
that create/destroy object they told me that I don''t use it correctly,
I can''t comment on that without seeing the code.
that I don''t call destructor etc etc....
So, what are the possible scopes destructors may have?
Those you enumerated above.
-Mike
In article <11*********************@g44g2000cwa.googlegroups. com>,
__PPS__ <i-*********@yandex.ru> wrote:Hello everybody,
in my exam in c++ I answered that destructors may be declared private,
public or protected.
The question was: "What possible scopes (public or private) can a
destructor have?"
I got 0 for this answer, they corrected me that destructor can only be
public.
When I showed the code with private destructor and friend functions
that create/destroy object they told me that I don''t use it correctly,
that I don''t call destructor etc etc....
So, what are the possible scopes destructors may have?
Since the question asked about *scope* the correct answer
is "class scope".
However, it sounds like your question was about accessibility,
that is *access*. In that case, usually you don''t want it to be,
but sure a dtor can be private. Of course, the case of not
using something properly is not always the same as if it''s possible.
If you want a critique of your private dtor code here, feel
free to post it, in the meantime, the person giving you the
exam has apparently used wrong terminology.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware''s Libraries... Have you tried it?
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:Hh**************@newsread2.news.pas.earthlink .net...
"__PPS__" <i-*********@yandex.ru> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...Hello everybody,
in my exam in c++ I answered that destructors may be declared private,
public or protected.
The question was: "What possible scopes (public or private) can a
destructor have?"
I got 0 for this answer, they corrected me that destructor can only be
public.
You''re right, they''re wrong.
But Greg is more right than either of us. :-)
I overlooked that misuse of terminology that
he noted.
-Mike
这篇关于析构函数的可能范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!