|
Boost : |
From: ÒÝÁØ Ñî (yyl_20050115_at_[hidden])
Date: 2020-07-31 20:09:59
A downgrade implementation can be like this
(which is actually my former implementation during the experiments)
We define an interface:
struct IDIsposable
{
virtual void Dispose() = 0;
};
And implement this interface with class A
class A : public IDisposable
{
Public;
A():disposed(false){}
public:
virtual void Dispose(){
if(!this->disposed){
this->_pb.Dispose();//this Dispose belongs to rcgc_shared_ptr
this->_pc.Dispose(); //this Dispose belongs to rcgc_shared_ptr
this->disposed = true;
}
}
bool disposed;
rcgc_shared_ptr<B> _pb;
rcgc_shared_ptr<C> _pc;
};
And we don¡¯t care about ~A() and let the rcgc_shared_ptr call Dispose method of the IDisposable.
This would avoid the dtors definition.
However, this is not as elegant as the previous given solution in C++,
having to write more code which we don¡¯t like to do,
although no difference in other languages or platforms.
I¡¯m sorry that I have to call it a day now and have to get some sleep (4:06am here)
Waiting for your kindly response and suggestions.
Best Regards,
Yilin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk