Guest User

Untitled

a guest
Dec 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include <algorithm>
  4.  
  5. class Renderable
  6. {
  7. public:
  8.  
  9.     Renderable()
  10.         :_priority(0)
  11.     {
  12.        
  13.     }
  14.     explicit Renderable( unsigned int priority)
  15.         :_priority(priority)
  16.     {
  17.        
  18.     }
  19.     bool operator< (const Renderable& b);
  20.  
  21.  
  22.     void SetPriority( unsigned int priority)
  23.     {
  24.         _priority = priority;
  25.     }
  26. private:
  27.     unsigned int _priority;
  28. };
  29.  
  30. bool Renderable::operator< (const Renderable& b)
  31. {
  32.     unsigned int _pri = b._priority;
  33.  
  34.     return _priority < _pri;
  35. }
  36.  
  37.  
  38.  
  39. int _tmain(int argc, _TCHAR* argv[])
  40. {
  41.  
  42.     Renderable foo(67);
  43.     Renderable bar(58);
  44.  
  45.     bool result = foo < bar;
  46.  
  47.  
  48.     Renderable a[10];
  49.     for( int i = 0; i < 10; ++i)
  50.     {
  51.         unsigned int num = rand();
  52.         a[i].SetPriority(num);
  53.     }
  54.  
  55.  
  56.     std::sort<Renderable*>(a+0, a+10);
  57.  
  58.  
  59.     return 0;
  60. }
Add Comment
Please, Sign In to add comment