创建对象的方法数 [英] Number of ways to create an object

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

问题描述

一位朋友被问到在C ++中创建一个对象有多少种方式?

在一次采访中。显然,正确是指正确。答案是十一点。

有人知道面试官是如何得出这个号码的吗?这是事实

众所周知(如果是真的)?

A friend was asked "How many ways are there to create an object in C++?"
in an interview. Apparently, the "right" answer was eleven. Does
anyone know how the interviewer arrived at that number? Is this fact
well known (if true)?

推荐答案

2004年1月29日星期四10 :40:44 -0800,Peter Ammon< pe ********* @ rocketmail.com>写道:
On Thu, 29 Jan 2004 10:40:44 -0800, Peter Ammon <pe*********@rocketmail.com> wrote:
一位朋友被问到在C ++中有多少种方法可以创建一个对象?
在一次采访中。


唯一有意义的答案是1:通过调用构造函数。


为了避免白痴再次反对该术语:它是一个雇用

由神圣标准。


显然,正确的答案是十一点。有没有人知道面试官是如何得出这个数字的?这个事实是否众所周知(如果是真的)?
A friend was asked "How many ways are there to create an object in C++?"
in an interview.
The only meaningful answer is 1: by calling a constructor.

Lest idiots yet again object to that terminology: it''s the one employed
by the Holy Standard.

Apparently, the "right" answer was eleven. Does
anyone know how the interviewer arrived at that number? Is this fact
well known (if true)?




在适当的假设下任何数字都可能被认为是正确的并且

使用合适的定义,例如方法,创建,对象等。



Any number might be considered correct under suitable assumptions and
using suitable definitions, e.g. of "ways", "create", "object".




Peter Ammon < PE ********* @ rocketmail.com>在消息中写道

新闻:bv ********** @ news.apple.com ...

"Peter Ammon" <pe*********@rocketmail.com> wrote in message
news:bv**********@news.apple.com...
一位朋友被问到有多少种方法是否在C ++中创建一个对象?
在一次采访中。显然,正确是指正确。答案是十一点。有没有人知道面试官是如何得出这个数字的?这个事实是否众所周知(如果是真的)?
A friend was asked "How many ways are there to create an object in C++?"
in an interview. Apparently, the "right" answer was eleven. Does
anyone know how the interviewer arrived at that number? Is this fact
well known (if true)?




那个事实如果是真的,那就不为人知。听起来像那些愚蠢的问题之一

问题,面试官有一个一个人的问题。已经提前研究了一个你不知道的

模糊问题。也许他只是想要

看看你如何看待事情并让球滚动,而不是想出

" 11"。 (坦率地说,我现在想起了这就是脊柱水龙头。)


A级;


A a; // 1

A * pA =新A; // 2

f(A()); // 3




That "fact" is not well known, if true. Sounds like one of those goofy
questions where the interviewer has a "one up" by already researching an
obscure problem ahead of time that you couldn''t know. Maybe he just wanted
to see how you think about things and get the ball rolling, not come up with
"11". (Frankly, I''m reminded of This Is Spinal Tap at this moment.)

class A;

A a; // 1
A* pA = new A; // 2
f(A()); // 3
etc.




" Alf P. Steinbach" <人*** @ start.no>在留言新闻中写道:40 **************** @ News.CIS.DFN.DE ...

"Alf P. Steinbach" <al***@start.no> wrote in message news:40****************@News.CIS.DFN.DE...
2004年1月29日星期四10:40 :44 - 0800,Peter Ammon< pe ********* @ rocketmail.com>写道:
On Thu, 29 Jan 2004 10:40:44 -0800, Peter Ammon <pe*********@rocketmail.com> wrote:
一位朋友被问到用C ++创建一个对象有多少种方法?
在一次采访中。
唯一有意义的答案是1:通过调用构造函数。
A friend was asked "How many ways are there to create an object in C++?"
in an interview.
The only meaningful answer is 1: by calling a constructor.




这是错的。你不能称之为构造函数。构造函数由

实现调用,作为创建对象的副产品。

Lest idiots再次反对该术语:它是被雇用的那个
按照神圣的标准。



It''s wrong. You can''t call the constructor. A constructor is called by the
implementation as a byproduct of object created.
Lest idiots yet again object to that terminology: it''s the one employed
by the Holy Standard.




不,不是。即使你的争吵被称为经文打电话

你的回答是错误的。对象

创建中有两个DISTINCT步骤,具体列在标准中:


1.获得第一个存储空间

2。然后施工。


你的错误答案完全省略了第一步。



No it''s not. Even with your quibbling over "is called" verses "calling"
your answer is WRONG. There are two DISTINCT steps in object
creation specifically listed in the standard:

1. First storage is obtained
2. Then construction occurs.

Your incorrect answer totally omits the first step.


这篇关于创建对象的方法数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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