Code

address type-punned pointer warning
authormental <mental@users.sourceforge.net>
Fri, 9 Mar 2007 00:32:53 +0000 (00:32 +0000)
committermental <mental@users.sourceforge.net>
Fri, 9 Mar 2007 00:32:53 +0000 (00:32 +0000)
src/gc-soft-ptr.h

index a055ba38c18342dd8b7d39f4c3210cee1807c267..539eac678553dd212672db4c39136075334627ea 100644 (file)
@@ -27,19 +27,16 @@ namespace GC {
 template <typename T>
 class soft_ptr {
 public:
-    soft_ptr(T * const &pointer=NULL) : _pointer(pointer) {
-        _register();
-    }
-    soft_ptr(soft_ptr const &other) : _pointer(other._pointer) {
+    soft_ptr(T *pointer=NULL) : _pointer(pointer) {
         _register();
     }
 
-    operator T *() const { return _pointer; }
-    T &operator*() const { return *_pointer; }
-    T *operator->() const { return _pointer; } 
-    T &operator[](int i) const { return _pointer[i]; }
+    operator T *() const { return static_cast<T *>(_pointer); }
+    T &operator*() const { return *static_cast<T *>(_pointer); }
+    T *operator->() const { return static_cast<T *>(_pointer); } 
+    T &operator[](int i) const { return static_cast<T *>(_pointer)[i]; }
 
-    soft_ptr &operator=(T * const &pointer) {
+    soft_ptr &operator=(T *pointer) {
         _pointer = pointer;
         return *this;
     }
@@ -50,11 +47,11 @@ private:
     void _register() {
         void *base=Core::base(this);
         if (base) {
-            Core::general_register_disappearing_link((void **)&_pointer, base);
+            Core::general_register_disappearing_link(&_pointer, base);
         }
     }
 
-    T *_pointer;
+    void *_pointer;
 };
 
 }