Advertisement
Guest User

Untitled

a guest
May 7th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.69 KB | None | 0 0
  1. module foo;
  2.  
  3. import std.stdio;
  4.  
  5. class Foo
  6. {
  7.     private this ()
  8.     {
  9.         writeln("ads");
  10.     }
  11. }
  12.  
  13. module test;
  14.  
  15. import std.stdio;
  16. import foo;
  17.  
  18. version (LDC)
  19.     extern (C) Object _d_allocclass(ClassInfo);
  20.  
  21. else
  22.     extern (C) Object _d_newclass(ClassInfo);
  23.        
  24. Object newInstance (ClassInfo classInfo)
  25. {
  26.     version (LDC)
  27.     {        
  28.         Object object = _d_allocclass(classInfo);
  29.         (cast(byte*) object)[0 .. classInfo.init.length] = classInfo.init[];
  30.        
  31.         return object;
  32.     }
  33.  
  34.     else
  35.         return _d_newclass(classInfo);
  36. }
  37.  
  38. void main()
  39. {
  40.     auto f = cast(Foo) newInstance(Foo.classinfo);
  41.     auto a = &f.__ctor;
  42.     a();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement