473,836 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set a pointer to null when deleting?

When you delete a pointer, you should set it to NULL, right?

Joe
Apr 10 '06
51 10549
Noah Roberts wrote:
Paul M. Dubuc wrote:
Victor Bazarov wrote:
Phlip wrote:
If you must, use std::auto_ptr or boost::shared_p tr, and reset(NULL)
that (if I recall correctly).
'boost' is non-standard. 'std::auto_ptr' is not suitable for some
cases due to its particular copy semantics.

No reason not to use boost. Besides, boost smart pointers have been accepted
into TR1, so they are standard and will be supported by newer compilers.


wrong.

"This technical report is non-normative. Some of the library components
in this technical report may be considered for standardization in a
future version of C++, but they are not currently part of any C++
standard. Some of the components in this technical report may never be
standardized, and others may be standardized in a substantially changed
form."


Thanks for the correction. I see there are no promises about promoting
std::tr1:: into std:: but, practically speaking, this is still no reason not
to use boost or tr1 components.

--
Paul M. Dubuc
Apr 13 '06 #51

Paul M. Dubuc wrote:
Noah Roberts wrote:
Paul M. Dubuc wrote:
Victor Bazarov wrote:
Phlip wrote:
> If you must, use std::auto_ptr or boost::shared_p tr, and reset(NULL)
> that (if I recall correctly).
'boost' is non-standard. 'std::auto_ptr' is not suitable for some
cases due to its particular copy semantics.
No reason not to use boost. Besides, boost smart pointers have been accepted
into TR1, so they are standard and will be supported by newer compilers.


wrong.

"This technical report is non-normative. Some of the library components
in this technical report may be considered for standardization in a
future version of C++, but they are not currently part of any C++
standard. Some of the components in this technical report may never be
standardized, and others may be standardized in a substantially changed
form."


Thanks for the correction. I see there are no promises about promoting
std::tr1:: into std:: but, practically speaking, this is still no reason not
to use boost or tr1 components.


I agree, and I hope at least smart pointers make it into the standard.
Unfortunately it will be a long time from now before that happens and
even longer before commercial compilers catch up. I prefer to rely on
library versions of such things but since it is not in the standard
yaddda yadda, I have to write my own sometimes.

Apr 13 '06 #52

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2346
by: Asfand Yar Qazi | last post by:
Hello. Partly for learning purposes, I have written a smart pointer class. Could you please tell me what's wrong with it? (I know there's something wrong with it, but just not what!) Note that, as well as reference counting the stored pointer, it also has the ability to be declared for incomplete types (I think). I.e.: struct Incomplete;
2
1370
by: nifsmith | last post by:
Hi I am creating my own Queue class to learn about Queues and pointers. I have come across a question of two styles and I don't know if there are any dangers associated with them. I coded my remove function as follows template <class T>
3
9634
by: Songling | last post by:
Hi gurus, Just learnt from my co-worker that it's safe to delete a null pointer. I tried it on sun box (and linux), nothing bad happens. So it seems to be true. But does it apply to all platforms? Also if I delete a pointer twice, and don't nullify the pointer after the first delete, it's going to trap. If I do the nullify, no trap. Does it just confirm that it's safe
4
3104
by: Venn Syii | last post by:
I've searched all the forums but cannot find an answer to this question. I do the following: vector<MyClass*> myClassList; Later in the program I try to add to myClassList with a .push_back(...) I get an "out of memory" runtime error. I know I'm not out of memory because normal vectors such as vector<int> a, still work, and still work fine.
3
3411
by: John Ratliff | last post by:
When I dereference a pointer, does it make a copy of the object? Say I had a singleton, and wanted an static method to retrieve it from the class. class foo { private: static foo *bar; foo() {} // no public creation!
6
3029
by: KWienhold | last post by:
I'm currently working on a project in C# (VS 2003 SP1, .Net 1.1) that utilizes IStream/IStorage COM-Elements. Up to now I have gotten everything to work to my satisfaction, but now I have come across a problem I can't really explain: When deleting an object from an IStorage, the space it used up will not be freed, but rather marked as unused and overwritten the next time you add an object to the storage. This is obviously working as...
30
2753
by: Jess | last post by:
Hello, I tried a program as follows: include<iostream> using namespace std; class A{ public:
6
1996
by: ma740988 | last post by:
Given the snippet. class foo { public: ~foo() { // type id should be able to get the type of the class ( I think ) std::cout << " foo destructing " << std::endl; } };
8
6140
by: Rahul | last post by:
Please read the following code class Test{ public: void * operator new (size_t t) { return malloc(t); } void operator delete (void *p) { free(p); } };
0
9816
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6978
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.