This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: D  |  size: 0.69 KB  |  views: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data