Advertisement
jewalky

Untitled

Feb 15th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. class UnrelatedClass
  2. {
  3.     static void TestFunc()
  4.     {
  5.    
  6.     }
  7. }
  8.  
  9. class MySafeClass
  10. {
  11.    
  12. }
  13.  
  14. class MyUnsafeClass unsafe
  15. {
  16.    
  17. }
  18.  
  19. class TestInventory : Inventory
  20. {
  21.     unsafe int a;
  22.     int b;
  23.  
  24.     virtual unsafe void TestFunc2()
  25.     {
  26.         // dummy function to test virtual unsafety below
  27.     }
  28.    
  29.     override bool DrawPowerup(int x, int y)
  30.     {
  31.         MyUnsafeClass cls = new('MyUnsafeClass'); // should work
  32.         MySafeClass cls = new('MySafeClass'); // should fail
  33.    
  34.         a = 1; // should work
  35.         b = 2; // should fail
  36.         UnrelatedClass.TestFunc(); // should fail
  37.        
  38.         textureID tx = TexMan.CheckForTexture("M_DOOM", TexMan.TYPE_Any); // should work
  39.         Screen.DrawHUDTexture(tx, 0, 0); // should work
  40.         return true;
  41.     }
  42. }
  43.  
  44. class TestInventory2 : TestInventory
  45. {
  46.     void TestFunc1()
  47.     {
  48.         a = 1; // should work
  49.         b = 2; // should work
  50.     }
  51.  
  52.     // test unsafe inheritance
  53.     override void TestFunc2()
  54.     {
  55.         a = 1; // should work
  56.         b = 2; // should fail
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement