[Gc] Using GC in C++ via multiple inheritance

Shriramana Sharma samjnaa at gmail.com
Fri Apr 12 22:12:27 PDT 2013


Hello. I've been refactoring parts of Asymptote (asymptote.sf.net)
code for inclusion into my own project and was hence introduced to GC.
I understand that by subclassing a new class I create say MyClass from
class gc, instances of MyClass will be garbage collected since
operator new for it is now overloaded to use GC_MALLOC. However, I'd
like to clarify one thing:

If I have to create MyClass as a subclass of a LibraryClass which
doesn't use gc, is it sufficient for me to multiply inherit from gc
and do:

class MyClass : public LibraryClass, public gc {
...
} ;

so that new-ed instances of MyClass will be garbage collected
including the LibraryClass sub-objects within them? I hope so, but I
didn't want to assume, so am asking for this clarification here.

Note that I am not an expert programmer, only an intermediate one, so
I may require more explanations than others. Thank you for your time
and patience.

--
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा



More information about the Gc mailing list