]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
allow multiple inheritance with Refcounted classes
authorrobertc <>
Fri, 13 Dec 2002 10:41:28 +0000 (10:41 +0000)
committerrobertc <>
Fri, 13 Dec 2002 10:41:28 +0000 (10:41 +0000)
include/RefCount.h
test-suite/refcount.cc

index 8155179c47da01f1d4101bdc8b33a0033e51d732..911e1252d82f150ae9549cc237b9574e09bf4b2f 100644 (file)
@@ -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_ */
index 317bfa6ce0aea206cc2e39ce5ecf60e9a62fbf4e..02fab28461cc1b43434ba1ac5f4354917a799513 100644 (file)
@@ -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<AlsoRefCountable> 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;
 }