From: robertc <> Date: Fri, 13 Dec 2002 10:41:28 +0000 (+0000) Subject: allow multiple inheritance with Refcounted classes X-Git-Tag: SQUID_3_0_PRE1~496 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=128ef305825f65a76351f736c5ac58f4d507729b;p=thirdparty%2Fsquid.git allow multiple inheritance with Refcounted classes --- diff --git a/include/RefCount.h b/include/RefCount.h index 8155179c47..911e1252d8 100644 --- a/include/RefCount.h +++ b/include/RefCount.h @@ -1,6 +1,6 @@ /* - * $Id: RefCount.h,v 1.1 2002/11/21 12:35:53 robertc Exp $ + * $Id: RefCount.h,v 1.2 2002/12/13 03:41:28 robertc Exp $ * * DEBUG: section xx Refcount allocator * AUTHOR: Robert Collins @@ -81,10 +81,10 @@ private: }; -struct RefCountable +struct RefCountable_ { - RefCountable():count_(0){} - virtual ~RefCountable(){} + RefCountable_():count_(0){} + virtual ~RefCountable_(){} virtual void deleteSelf() const = 0; /* Not private, to allow class hierarchies */ void RefCountReference() const { ++count_; } @@ -93,4 +93,6 @@ private: mutable unsigned count_; }; +#define RefCountable virtual RefCountable_ + #endif /* _SQUID_REFCOUNT_H_ */ diff --git a/test-suite/refcount.cc b/test-suite/refcount.cc index 317bfa6ce0..02fab28461 100644 --- a/test-suite/refcount.cc +++ b/test-suite/refcount.cc @@ -1,6 +1,6 @@ /* - * $Id: refcount.cc,v 1.1 2002/11/21 12:35:53 robertc Exp $ + * $Id: refcount.cc,v 1.2 2002/12/13 03:41:28 robertc Exp $ * * DEBUG: section xx Refcount allocator * AUTHOR: Robert Collins @@ -52,6 +52,12 @@ typedef RefCount<_ToRefCount> ToRefCount; /* Must be zero at the end for the test to pass. */ int _ToRefCount::Instances = 0; +class AlsoRefCountable : public RefCountable, public _ToRefCount { + public: + typedef RefCount Pointer; + int doSomething() { if (!this) exit (1); return 1;} +}; + int main (int argc, char **argv) { @@ -113,5 +119,16 @@ main (int argc, char **argv) _ToRefCount *aPointer = anObject.getRaw(); aPointer = NULL; } + /* Create a doubley inheriting refcount instance, + * cast to a single inheritance instance, + * then hope :} + */ + { + ToRefCount aBaseObject; + { + AlsoRefCountable::Pointer anObject (new AlsoRefCountable); + aBaseObject = anObject.getRaw(); + } + } return _ToRefCount::Instances == 0 ? 0 : 1; }