将从new返回的地址分配给引用 [英] Assigning the address returned from new to a reference

查看:52
本文介绍了将从new返回的地址分配给引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以写:


T i& = new T;


谢谢!!!

Can I write:

T i&=new T;

Thanks!!!

推荐答案

Protoman schrieb:
Protoman schrieb:
我可以写一下:
T i& = new T;
Can I write:
T i&=new T;



当然你可以写这个;但没有conformat编译器会接受这个。而且我认为这不是你想问的问题;

我想你想问一下这样的事情......


T& t = *新的T();


....是合法的。它是!



Of course you can write this; but no conformat Compiler will
accept that. And I think its not the thing you wanted to ask;
I think you wanted to ask if something like ...

T &t = *new T();

.... is legal. It is!


Protoman写道:
Protoman wrote:
我可以写:

T i& = new T;

谢谢!!!
Can I write:

T i&=new T;

Thanks!!!




我想你的意思是

T& i = new T;


为什么你不写一个小程序看看会发生什么?



I think you meant
T &i = new T ;

Why don''t you write a small program and see what happens ?


" Oliver S." <佛******* @ gmx.net>在消息中写道

news:43 *********************** @ newsread2.arcor-online.net ...
"Oliver S." <Fo*******@gmx.net> wrote in message
news:43***********************@newsread2.arcor-online.net...
Protoman schrieb:
Protoman schrieb:
我可以写:
T i& = new T;
Can I write:
T i&=new T;



当然你可以写这个;但没有conformat Compiler会接受这个。而且我认为这不是你想问的问题;
我想你想问一下这样的事情......

T& t = * new T();

......是合法的。它是!



Of course you can write this; but no conformat Compiler will
accept that. And I think its not the thing you wanted to ask;
I think you wanted to ask if something like ...

T &t = *new T();

... is legal. It is!




你会如何删除它?

我不相信你可以删除引用,是吗?我不相信

删除t

会编译(虽然我可能会测试并查看)



How would you delete it?
I don''t believe you can delete a reference, can you? I don''t believe
delete t
would compile (although I might test it and see)


这篇关于将从new返回的地址分配给引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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