|
Boost : |
From: SourceForge.net (noreply_at_[hidden])
Date: 2005-07-22 02:30:42
Bugs item #1242857, was opened at 2005-07-22 00:30
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1242857&group_id=7586
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: smart_ptr
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Peter Dimov (pdimov)
Summary: Can't delete automatically in circularly included object.
Initial Comment:
hi,all:
I am a chinese student.Please forgive me because of
my poor english.
I found an error on smart pointer shared_ptr when i add
an shared_ptr object to itself.
The code is below.Class StatusBase is a subclass of
Status.There is a method name addEventResult in class
StatusBase. As you can see, EventResult is an object
which made up of object Status( StatusBase actually
because of Status is an abstract class ),Action and
Event.In the case, I try to let them passed in share_ptr
wrpper whenever in constructor or normal method.As my
opinion,I think that will not be error and when I exit my
program it will free the memory for me automatically.
But in fact it will not.
shared_ptr<Status> A( new Status() );
shared_ptr<Event> B( new Event() );
shared_ptr<Action> C( new Action() );
shared_ptr<EventResult> ABC( new
EventResult( A, B, C ) );
//the row below will result the object A can't
be released, so as to the object ABC , B and C
A.addEventResult( ABC );
//next is about the decleartion of StatusBase
and EventResult. For class Event and Action, it is the
history.
class StatusBase : public Status //{{{
{
public:
StatusBase(){}
virtual ~StatusBase(){}
public:
int getEventResultCount() const ;
boost::shared_ptr<EventResult>
getEventResult( int index ) const ;
void addEventResult( const
boost::shared_ptr<EventResult>& v ) ;
private:
std::vector<
boost::shared_ptr<EventResult> > events ;
}; //}}}
class EventResult : public pqkit::Object //{{{
{
public:
EventResult( const
boost::shared_ptr<Event>& e, const
boost::shared_ptr<Action>& a, const
boost::shared_ptr<Status>& s ) : event(e),action
(a),newStatus(s){}
virtual ~EventResult() {}
public:
virtual const std::string
toString() const
{
return
Object::toString() ;
}
virtual const
pqkit::Class getClass() const
{
return
pqkit::Class("EventResult","inhert:Object->EventResult");
}
boost::shared_ptr<Event> getEvent() const {
return event; }
boost::shared_ptr<Action> getAction() const
{ return action; }
boost::shared_ptr<Status> getNewStatus()
const { return newStatus; }
private:
boost::shared_ptr<Event> event ;
boost::shared_ptr<Action> action ;
boost::shared_ptr<Status> newStatus ;
}; //}}}
yours JinheZeng at GDUT from China.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1242857&group_id=7586
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Boost-bugs mailing list
Boost-bugs_at_[hidden]
https://lists.sourceforge.net/lists/listinfo/boost-bugs
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk