🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by corfmanr Thu, 07 Dec 1995 18:35
auto_ptr<X> questions
#2881
Author: corfmanr
Date: Thu, 07 Dec 1995 18:35
49 lines
1555 bytes
I implemented a version of the auto_ptr<X> template class
for the interim until the compiler I use offers one.

I'm not sure how to protect against something like the
following:

	auto_ptr<int> p(new int);
	delete p.reset(p.get());

Now I know the above is stupid and I would hope nobody would
actually do it, but I think it is a good pedagogical example
of a problem that may occur. To overcome this problem, I
coded up the reset method as follows:

template<class X> class auto_ptr
{
	X* ptr;
public:
	...
};

template<class X>
X* auto_ptr<X>::reset(X* p)
{
	if (p == ptr)
		return 0;

	X* pt = ptr;
	ptr = p;
	return pt;
}

I'd like to get some comments on if this is a reasonable and valid
way to implement the reset method. How has anyone else handled this
situation.

Thanks,
--
Russell Corfman
AG Communication Systems              Internet: corfmanr@agcs.com
P.O. Box 52179                           Voice: (602) 581-4403
Phoenix, AZ 85072-2179                     Fax: (602) 582-7111


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads