Loading

Paste #pcgvcrfo1

  1. int main()
  2. {
  3.     SafeReference<Room> room_ref1;
  4.     printf("&room_ref1 = %p\n", &room_ref1);
  5.     printf("\troom_ref1 valid: %d\n", room_ref1.IsValid());
  6.  
  7.     {
  8.         printf("\nEntering sub-scope\n");
  9.  
  10.         Room room;
  11.         printf("&room = %p\n", &room);
  12.  
  13. #ifdef DBG_SAFE_REF
  14.         room.DumpReferences();
  15. #endif
  16.  
  17.         room_ref1 = room.GetReference();
  18.         printf("\troom_ref1 valid: %d\n", room_ref1.IsValid());
  19.         if (room_ref1.IsValid()) printf("\tRef points to %p\n", room_ref1.GetObject());
  20. #ifdef DBG_SAFE_REF
  21.         room.DumpReferences();
  22. #endif
  23.  
  24.         printf("\nAdding 2nd room ref\n");
  25.         SafeReference<Room> room_ref2 = room.GetReference();
  26.         printf("&room_ref2 = %p\n", &room_ref2);
  27.         printf("\troom_ref2 valid: %d\n", room_ref1.IsValid());
  28. #ifdef DBG_SAFE_REF
  29.         room.DumpReferences();
  30. #endif
  31.  
  32.         printf("\nMoving references\n");
  33.         room_ref1 = std::move(room_ref2);
  34.  
  35.         printf("\nLeaving sub-scope\n");
  36.     }
  37.  
  38.     printf("\troom_ref1 valid: %d\n", room_ref1.IsValid());
  39.     return 0;
  40. }

Comments