怎么避免? [英] How to avoid?

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

问题描述

A级;


A * a =新A;


A * b,* c;


b = a;

c = b;


删除a;

删除b;

删除c;

这是dangrous ..可以任何人给出解决方案以避免倍数

删除??


1)删除后将其设为NULL

2)任何其他解决方案??????

class A;

A *a = new A;

A *b, *c;

b= a;
c= b;

delete a;
delete b;
delete c;
This is dangrous..can any one give the solution to avoid multipl
delete??

1) Make it NULL after delete
2) Any other solution??????

推荐答案

< a href =mailto:do ************* @ gmail.com>做************* @ gmail.com 写道:
do*************@gmail.com wrote:

A级;


A * a =新A;


A * b,* c;


b = a;

c = b;


删除a;

删除b;

删除c;


这是dangrous ..可以任何人给出解决方案以避免倍数

删除??


1)删除后将其设为NULL

2)任何其他解决方案??????
class A;

A *a = new A;

A *b, *c;

b= a;
c= b;

delete a;
delete b;
delete c;
This is dangrous..can any one give the solution to avoid multipl
delete??

1) Make it NULL after delete
2) Any other solution??????



注重细节。


-

Ian Collins。

Attention to detail.

--
Ian Collins.


做************ *@gmail.com 写道:

A级;


A * a =新A;


A * b,* c;


b = a;

c = b;


删除a;

删除b;

删除c;


这是dangrous ..可以任意一个给出解决方案以避免倍数

删除??


1)删除后使其为NULL

2)任何其他解决方案??????
class A;

A *a = new A;

A *b, *c;

b= a;
c= b;

delete a;
delete b;
delete c;
This is dangrous..can any one give the solution to avoid multipl
delete??

1) Make it NULL after delete
2) Any other solution??????



智能指针。我在*年*之内的其他任何地方都没有写删除。

智能指针类*。


Andy

Smart pointers. I haven''t written a delete anywhere else than inside a
smart pointer class in *years*.

Andy




智能指针在现实世界中并不总是理想的解决方案。

首先,它们的实时/任务成本很高 - 关键

系统。此外,它们不能轻易引入传统的

系统 - 一个例子就是我工作的公司。最初的

平台是至少15年前在C开发的。加班时间,它已经显着移植到C ++(现在,我们大多添加了

功能,并维护产品)。我在每日

的基础上使用指针。

职位描述中没有愚蠢和笨拙的指示。


最后,新一代boost和RT1智能指针太新了

100%依赖。我建议使用它们,除非管理层

并且完全了解其后果和影响。

至于你的问题域,如果智能指针实际上是允许的,

选择以下其中一项(或自己动手):


std :: auto_ptr<>

std :: tr1 :: shared_ptr<>

std :: tr1 :: weak_ptr<>

boost :: intrusive_ptr<>

boost :: scoped_ptr< >

boost :: scoped_array<>,boost :: shared_array<>

std :: unique_ptr<>

PuzzleCracker

Smart pointers are not always an ideal solution in the real world.
First of all, they are expensive in real-time/mission-critical
systems. Additionally, they cannot be easily introduced into legacy
systems-- one example is the company where I work. The original
platform was developed at least 15 years ago, in C. And overtime, it
has been significantly ported to C++ ( These days, we mostly add
features, and maintain the product). I work with pointers on daily
basis. And not being stupid and clumsy with pointers is included in
job description.

Lastly, the new generation boost and RT1 smart pointers are too new
to be 100% relied on. I would recommend using them unless management
and fully aware of ramifications and implications.
As for your problem domain, if a smart pointer is in fact permissible,
choose one one of the following (or roll your own):

std::auto_ptr<>
std::tr1::shared_ptr<>
std::tr1::weak_ptr<>
boost::intrusive_ptr<>
boost::scoped_ptr<>
boost::scoped_array<>, boost::shared_array<>
std::unique_ptr<>
PuzzleCracker


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

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