构造函数是一个函数吗? [英] Is a constructor a function?

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

问题描述

隐藏在另一个帖子中,问题出现了:


构造函数是函数吗?


(My索赔是不,虽然有些人不同意。)


非常感谢,

--ag


[是的,我知道他们做了什么以及如何调用它们。我正试图从语言律师的角度得到一个

答案。]

-

Artie Gold - 奥斯汀,Texas

Hidden in another thread, the question has come up:

"Is a constructor a function?"

(My claim is "no", though some have disagreed.)

Many thanks,
--ag

[Yes, I know what they do and how they are invoked. I''m trying to get an
answer from a `language lawyer'' perspective.]
--
Artie Gold -- Austin, Texas

推荐答案

文章< 3F ************** @ austin.rr .com>, ar*******@austin.rr.com

说...
In article <3F**************@austin.rr.com>, ar*******@austin.rr.com
says...
隐藏在另一个帖子中,问题出现了:

构造函数是一个函数吗?
Hidden in another thread, the question has come up:

"Is a constructor a function?"




是的,一个ctor是一个函数,但是(尽管有些出现在

相反的情况下)没有名字。标准的相关部分是

第12.1节,如果您需要更详细地查看它。


-

后来,

杰瑞。


宇宙是自己想象的虚构。



Yes, a ctor is a function, but (despite some appearances to the
contrary) does not have a name. The relevant part of the standard is
section 12.1, in case you care to look at it in more detail.

--
Later,
Jerry.

The universe is a figment of its own imagination.


2003年8月6日星期三格林尼治标准时间13:05:26,Jerry Coffin< jc ***** @ taeus.com>写道:
On Wed, 06 Aug 2003 13:05:26 GMT, Jerry Coffin <jc*****@taeus.com> wrote:
是的,一个ctor是一个函数,但是(尽管有一些相反的外观)没有名字。
Yes, a ctor is a function, but (despite some appearances to the
contrary) does not have a name.




嗯,这不完全正确。除了

在构造过程中不能明确调用ctor,因为它没有代码可见的名称,但它确实

通过名称修改来命名。即建设者


class foo

{

public:

foo();

foo(int i);

};


是两个不同的函数,就链接器而言具有独特的名称/>
令人担忧。



Well, that''s not entirely true. The ctor can''t be called explicitly except
during construction because it has no name visible to the code, but it does
have a name through name mangling. i.e. the constructors

class foo
{
public:
foo();
foo(int i);
};

are two different functions, and have distinctive names as far as the linker
is concerned.


2003年8月6日星期三00:37:42 GMT,Artie Gold< ar **** ***@austin.rr.com>

写道:
On Wed, 06 Aug 2003 00:37:42 GMT, Artie Gold <ar*******@austin.rr.com>
wrote:
"构造函数是一个函数吗?"

(我的主张是不,虽然有些人不同意。)
"Is a constructor a function?"

(My claim is "no", though some have disagreed.)



是的,构造函数是一个函数。如果一个构造函数不是
函数,那究竟是什么呢?


更重要的是...... 12:1:The默认构造函数(12.1),复制

构造函数和复制赋值运算符(12.8),以及析构函数(12.4)

是特殊成员函数。


此外,12.1:1:构造函数没有名称和12.1:2:

" ... Becasue构造函数没有名称,在名称查找过程中找不到它们

,意思是他们不能被明确地称呼。代码

如:


A级{/ * ... * /};


A( );


是合法的,因为它允许12.1:13:功能符号类型

转换可用于创建其类型的新对象。 [注意:

语法看起来像构造函数的erxplicit调用]"

< / dib>

John Dibling
为保护而省略了Witty banter


Yes, a constructor is a function. If a constructor weren''t a
function, then what exactly would it be?

More to the point... 12:1: "The default constructor (12.1), copy
constructor and copy assignment operator (12.8), and destructor (12.4)
are special member functions."

In addition, 12.1:1: "Constructors do not have names" and 12.1:2:
"...Becasue constructors do not have names, they are never found
during name lookup...," meaning they can''t be called explicitly. Code
such as:

class A { /* ... */ } ;

A();

is legal because it is allowed by 12.1:13: "A functional notation type
conversion can be used to create new objects of its type. [Note: The
syntax looks like an erxplicit call of the constructor]"
</dib>
John Dibling
Witty banter omitted for your protection


这篇关于构造函数是一个函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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