Advertisement
Guest User

Untitled

a guest
May 12th, 2014
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. template <class T>
  2. class Counter {
  3. private:
  4.     T _initialValue;
  5.     T _value;
  6.    
  7. public:
  8.     Counter(T initialValue) {
  9.         _initialValue = initialValue;
  10.         reset();
  11.     };
  12.    
  13.     void reset() {
  14.         _value = _initialValue;
  15.     };
  16.    
  17.     void inc() {
  18.         _value++;
  19.     };
  20.    
  21.     T getValue() {
  22.         return _value;
  23.     };
  24. };
  25.  
  26.  
  27. Counter<int> intCnt(0);
  28. Counter<long> longCnt(0);
  29.  
  30. void setup() {
  31.     Serial.begin(115200);
  32. }
  33.  
  34. void loop() {
  35.     intCnt.inc();
  36.     longCnt.inc();
  37.     Serial.println(intCnt.getValue());
  38.     Serial.println(longCnt.getValue());
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement