Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class Counter {
- private:
- T _initialValue;
- T _value;
- public:
- Counter(T initialValue) {
- _initialValue = initialValue;
- reset();
- };
- void reset() {
- _value = _initialValue;
- };
- void inc() {
- _value++;
- };
- T getValue() {
- return _value;
- };
- };
- Counter<int> intCnt(0);
- Counter<long> longCnt(0);
- void setup() {
- Serial.begin(115200);
- }
- void loop() {
- intCnt.inc();
- longCnt.inc();
- Serial.println(intCnt.getValue());
- Serial.println(longCnt.getValue());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement