*新意味着什么? [英] What does * new mean?

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

问题描述

以下任务是做什么的?


SOME_TYPE& name = * new SOME_TYPE(* other_name);


一般情况下,当一个人写* new时他们在说什么?

谢谢。

What is the following assignment doing?

SOME_TYPE &name = *new SOME_TYPE ( *other_name);

In general, when one write "*new" What are they saying?
Thank you.

推荐答案

ma ************ @ gmail.com sade:
什么是以下作业在做什么?

SOME_TYPE& name = * new SOME_TYPE(* other_name);

一般来说,当写一个* new时他们在说什么?
谢谢。
What is the following assignment doing?

SOME_TYPE &name = *new SOME_TYPE ( *other_name);

In general, when one write "*new" What are they saying?
Thank you.




比较:


int * pi = new int;


int& i = * pi;


TB



Compare with:

int * pi = new int;

int & i = *pi;

TB


ma ************ @ gmail.com 写道:
以下任务是做什么的?

SOME_TYPE& name = * new SOME_TYPE(* other_name);

一般来说,当写一个* new时,他们在说什么?
What is the following assignment doing?

SOME_TYPE &name = *new SOME_TYPE ( *other_name);

In general, when one write "*new" What are they saying?




这不是作业。这是初始化。


新表达式前面的星号立即取消引用

新表达式返回的指针。因此,引用''name''

被初始化为引用动态对象指向

''new''返回的指针。


V



It''s not an assignment. It''s initialisation.

The asterisk in front of a ''new'' expression immediately dereferences
the pointer the ''new'' expression returns. So, the reference ''name''
is initialised to refer to the dynamic object a pointer to which the
''new'' returns.

V


< ma ************ @ gmail.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...
<ma************@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
以下作业是做什么的?

SOME_TYPE& name = * new SOME_TYPE(* other_name);

一般情况下,当写一个* new时;他们在说什么?
谢谢。
What is the following assignment doing?

SOME_TYPE &name = *new SOME_TYPE ( *other_name);

In general, when one write "*new" What are they saying?
Thank you.




正如其他两个家伙所说的那样取消引用允许名字的指针

初始化。


我自己的一个问题。这不会立即导致内存泄漏吗

这个内存永远不会被删除?


感谢Andrew



As the other two guys have said this dereferences the pointer to allow name
to be initialised.

One question of my own. Will this not instantly cause a memory leak since
this memory is never being deleted?

Thanks Andrew


这篇关于*新意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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