Advertisement
Guest User

Untitled

a guest
Sep 20th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.65 KB | None | 0 0
  1. import std.stdio;
  2.  
  3. struct A {
  4. public:
  5.     uint id;
  6.     uint data[128];
  7.    
  8.     this(uint id) {
  9.         this.id = id;
  10.        
  11.         writeln("CTor A with ", id);
  12.     }
  13.    
  14.     this(this) {
  15.         writeln("Postblit A with ", this.id);
  16.     }
  17.    
  18.     ~this() {
  19.         writeln("DTor A with ", this.id);
  20.     }
  21.    
  22.     A opBinary(string op : "+")(ref const A a) {
  23.         A r = A(this.id + a.id);
  24.         r.data[] += a.data[];
  25.         return r;
  26.     }
  27. }
  28.  
  29. void func(const A a) {
  30.     writeln("Value call with A::", a.id);  
  31. }
  32.  
  33. void func(ref const A a) {
  34.     writeln("Ref call with A::", a.id);
  35. }
  36.  
  37. void main()
  38. {
  39.     A a = A(42);
  40.     A b = A(23);
  41.    
  42.     asm { int 3; }
  43.     func(a + b);
  44.     asm { int 3; }
  45.     func(A(1337));
  46.     func(a);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement