C++:
class RefCounted
{
private:
i32 ref_count_;
public:
RefCounted()
{
ref_count_ = 1;
}
~RefCounted()
{
std::cout << "~RefCounted()\n";
}
void add_ref()
{
++ref_count_;
}
void release()
{
if (--ref_count_ == 0)
delete this;
}
};
Image::~Image()
{
...
std::cout << "~Image()\n";
}
class ASImage : public RefCounted, public Image
{
~ASImage()
{
cout << "~ASImage()\n";
}
};
AS:
void main()
{
Image@ img = Image();
}
Output:
~RefCounted()
Adding virtual to ~RefCounted()
fixed this.
Please add somewhere a information that class destructors when multiple inheritance must be virtual.