digitalmars.D.bugs - classinfo issue
- "Ben Hinkle" <bhinkle mathworks.com> Oct 19 2004
- Vathix <vathix dprogramming.com> Oct 19 2004
The documentation for stack allocation of classes has the line
Foo f = new(std.c.stdlib.alloca(Foo.classinfo.init.length)) Foo;
which works fine. The problem is when I try to Foo.classinfo in another
class. For example
class clsB {
new(uint sz, void* p){ return p; }
int x,y;
}
struct StorageFor(T:Object) {
ubyte[T.classinfo.init.length] data;
}
class clsA {
StorageFor!(clsB) storageForB;
clsB b;
this() {
b = new(&storageForB) clsB;
}
}
int main() {
clsA a = new clsA;
return 0;
}
it errors during the "semantic" phase that clsB doesn't has a property
'classinfo' (even if I remove the template). My guess is that the
classinfo's are valid only during a later semantic phase. It would be nice
to be able to use classinfo's for placing storage in other classes as well
as on the stack.
-Ben
Oct 19 2004
On Tue, 19 Oct 2004 12:10:49 -0400, Ben Hinkle <bhinkle mathworks.com> wrote:class clsB { new(uint sz, void* p){ return p; } int x,y; } struct StorageFor(T:Object) { ubyte[T.classinfo.init.length] data; } class clsA { StorageFor!(clsB) storageForB; clsB b; this() { b = new(&storageForB) clsB; } } int main() { clsA a = new clsA; return 0; }
Cool idea. (cast(TypeInfoClass)typeid(T)).info.init.length works, but it's not a constant.
Oct 19 2004








Vathix <vathix dprogramming.com>