Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 13th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. static ints, compilation units and the ternary operator
  2. class SomeCls
  3.     {
  4.     static const int PERIOD_ALARM_NORMAL    =   5;          
  5.     static const int PERIOD_ALARM_THRESH    =   1;          
  6.  
  7.     void method()
  8.     {
  9.         bool b = true;
  10.         const int d = b ? PERIOD_ALARM_THRESH : PERIOD_ALARM_NORMAL;
  11.     }
  12.  
  13.     } obj;
  14.        
  15. //SomeCls.cpp
  16. #include "SomeCls.h"
  17.  
  18. void SomeCls::method()
  19.     {
  20.         bool b = true;
  21.         const int d = b ? PERIOD_ALARM_THRESH : PERIOD_ALARM_NORMAL;
  22.     }
  23.        
  24. // I wish I had constexpr
  25. const int SomeCls::PERIOD_ALARM_NORMAL;
  26. const int SomeCls::PERIOD_ALARM_THRESH;
  27.        
  28. const int SomeCls::PERIOD_ALARM_NORMAL;
  29. const int SomeCls::PERIOD_ALARM_THRESH;
  30.        
  31. // someclass.h
  32. // include guards, blabla
  33.  
  34. class SomeClass
  35. {
  36.     enum AlarmPeriod{
  37.       PERIOD_ALARM_NORMAL = 5,
  38.       PERIOD_ALARM_THRESH = 1
  39.     };      
  40.  
  41. public:
  42.     void method();
  43. };
  44.  
  45. // someclass.cpp
  46. #include "someclass.h"
  47.  
  48. void SomeClass::method(){
  49.     bool b = true;
  50.     const int d = b ? PERIOD_ALARM_THRESH : PERIOD_ALARM_NORMAL;
  51. }
  52.  
  53. // main.cpp
  54. #include "someclass.h"
  55.  
  56. int main(){
  57.   someclass sc;
  58.   sc.method();
  59. }