Object Pointer
Namespace
rswhite4 at googlemail.com
Mon Jul 16 01:31:11 PDT 2012
I'm just experiement with D, that's all. ;)
Most of my questions here are just out of curiosity.
I have now this construct:
[code]
class smart_ptr {
private:
A* _ptr;
public:
this(A* ptr) {
void* buffer = GC.malloc(A.sizeof);
memcpy(buffer, ptr, A.sizeof);
this._ptr = cast(A*) buffer;
}
~this() {
GC.free(this._ptr);
}
@property
A* Ptr() {
return this._ptr;
}
alias Ptr this;
}
[/code]
And that is how i use it (ATM):
[code]
A a = new A(42);
smart_ptr sptr = new smart_ptr(&a);
sptr.echo();
a = null;
sptr.echo();
[/code]
But how can i free the memory?
Bizarrely it cannot be delete in the dtor. o.O
Strange design.
More information about the Digitalmars-d-learn
mailing list