Opened 17 years ago
Closed 13 years ago
#445 closed Feature Requests (wontfix)
Can't delete automatically in circularly included object.
Reported by: | nobody | Owned by: | Peter Dimov |
---|---|---|---|
Milestone: | To Be Determined | Component: | smart_ptr |
Version: | None | Severity: | Problem |
Keywords: | Cc: |
Description
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.
Change History (3)
comment:2 by , 15 years ago
Milestone: | → To Be Determined |
---|---|
Severity: | → Problem |
comment:3 by , 13 years ago
Resolution: | None → wontfix |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.