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(24): Error: class prog.Foo() is used as a type
prog.d(24): Error: variable prog.main.bar voids have no value
prog.d(24): Error: class prog.Foo() is used as a type
prog.d(24): Error: new can only create structs, dynamic arrays or class objects, not void's
prog.d(24): Error: cannot implicitly convert expression (new void) of type void* to int
stdout
Standard output is empty