diff --git a/lib/gir_ffi/class_base.rb b/lib/gir_ffi/class_base.rb
index <HASH>..<HASH> 100644
--- a/lib/gir_ffi/class_base.rb
+++ b/lib/gir_ffi/class_base.rb
@@ -73,7 +73,7 @@ module GirFFI
     def self.direct_wrap ptr
       return nil if !ptr || ptr.null?
       obj = allocate
-      obj.instance_variable_set :@struct, self::Struct.new(ptr)
+      obj.__send__ :store_pointer, ptr
       obj
     end
 
@@ -99,5 +99,11 @@ module GirFFI
     def self.constructor_wrap ptr
       direct_wrap ptr
     end
+
+    private
+
+    def store_pointer ptr
+      @struct = self.class::Struct.new(ptr)
+    end
   end
 end
Implement private ClassBase#store_pointer method