为什么POD不能有构造函数? [英] Why can't PODs have constructors?

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

问题描述

在实现级别必须有一些东西使得标准

禁止POD中的构造函数(?)。那是什么?不是大多数实现

只是将构造函数成员函数分解为construct_obj_x

非成员函数采用''this''ptr?


使用构造函数初始化结构肯定会很方便。

仍然让它们成为POD。


John

There must be something at the implementation level that makes the standard
disallow constructors in PODs (?). What is that? Don''t most implementations
just break out the constructor member functions into construct_obj_x
non-member functions taking a ''this'' ptr?

It sure would be convenient to initialize structs with constructors and
still having them be PODs.

John

推荐答案

JohnQ写道:
JohnQ wrote:

在实现级别必须有一些东西使

标准禁止POD中的构造函数(?)。那是什么?不是大多数

实现只是将构造函数成员函数分解为

construct_obj_x非成员函数采用''this''ptr?


使用构造函数初始化结构肯定会很方便。

仍然让它们成为POD。
There must be something at the implementation level that makes the
standard disallow constructors in PODs (?). What is that? Don''t most
implementations just break out the constructor member functions into
construct_obj_x non-member functions taking a ''this'' ptr?

It sure would be convenient to initialize structs with constructors and
still having them be PODs.



它会统治静态初始化。


-

Ian Collins。

It would rule out static initialisation.

--
Ian Collins.


2007年7月26日星期四05:44:28 -0500,JohnQ写道:
On Thu, 26 Jul 2007 05:44:28 -0500, "JohnQ" wrote:

>在实现级别必须有一些东西使标准
禁止POD中的构造函数(?)。这是什么?
使用构造函数初始化结构肯定会很方便,并且仍然将它们作为POD。
>There must be something at the implementation level that makes the standard
disallow constructors in PODs (?). What is that?
It sure would be convenient to initialize structs with constructors and
still having them be PODs.



内置类型有构造函数(例如int i(3);),你可以为POD结构编写

构造函数。 />
-

Roland Pibinger

最好的软件简单,优雅,充满戏剧性 - Grady Booch

Built-in types have constructors (e.g. int i(3);) and you can write
constructors for POD structs.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch


Roland Pibinger写道:
Roland Pibinger wrote:

On Thu,2007年7月26日05:44:28 - 0500,JohnQ写道:
On Thu, 26 Jul 2007 05:44:28 -0500, "JohnQ" wrote:

>在实现级别必须有一些东西使得
标准禁止POD中的构造函数(?)。这是什么?
使用构造函数初始化结构肯定会很方便
并且仍然将它们作为POD。
>There must be something at the implementation level that makes the
standard disallow constructors in PODs (?). What is that?
It sure would be convenient to initialize structs with constructors
and still having them be PODs.



内置类型有构造函数(例如int i(3);),你可以为POD结构编写

构造函数。


Built-in types have constructors (e.g. int i(3);) and you can write
constructors for POD structs.



我相信问题的原因是,一旦你为POD结构编写了
a构造函数,它就会停止成为POD结构。只需

你可能要记住的事情。


V

-

请在通过电子邮件回复时删除资本''A'

我没有回复最热门的回复,请不要问

I believe the reason for the question is that as soon as you write
a constructor for a POD struct, it stops being a POD struct. Just
something you might want to keep in mind.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


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

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