enum Reaction{single,chain};
class X
{
X* parent_;
X* left_;
X* right_;
Reaction* reaction_;//this pointer points from every obj to the same place, cannot be static
};
The Q is: how to design destructor in order to delete reaction_ only once?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Three immediate ideas:
1) Must reaction_ be owned by an instance of class X? Can’t it be owned by an external entity, so that no X::~X will ever need to delete it?
2) Use boost::shared_ptr
3) Implement your own reference counting using a static int. Remember locking if you’re multithreaded.