Created
February 24, 2014 08:11
-
-
Save stevenRush/9183712 to your computer and use it in GitHub Desktop.
Simple strategy pattern example with templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class ADVANCE_STRATEGY> | |
class base_iterator : ADVANCE_STRATEGY | |
{ | |
private: | |
int * pointer; | |
public: | |
base_iterator & operator++() | |
{ | |
advance(pointer); | |
} | |
}; | |
class straight_strategy | |
{ | |
void advance(int *& pointer) | |
{ | |
++pointer; | |
} | |
}; | |
class reverse_strategy | |
{ | |
void advance(int *& pointer) | |
{ | |
--pointer; | |
} | |
}; | |
typedef base_iterator<straight_strategy> iterator; | |
typedef base_iterator<reverse_strategy> reverse_iterator; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment