fork download
  1. import std.stdio;
  2.  
  3. class Foo
  4. {
  5. this() { writeln("ctor"); }
  6.  
  7. new(size_t size) {
  8. void* mem = malloc(size);
  9. if (!mem) throw new Exception("Failed alloc");
  10. return mem;
  11. }
  12.  
  13. ~this() { writeln("dtor"); }
  14.  
  15. delete(void* ptr)
  16. {
  17. free(ptr);
  18. }
  19. }
  20.  
  21. void main()
  22. {
  23. /* mallocated */
  24. Foo bar = new Foo();
  25. writeln("some program");
  26. clear(bar);
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.d(8): Error: undefined identifier malloc
prog.d(8): Error: function expected before (), not malloc of type int
Error: cannot implicitly convert expression (__error) of type int to void*
stdout
Standard output is empty