#include using namespace std; class Context;//Forward declaration class Strategy{ public: virtual void execute(Context* c)=0; }; class Strategy1: public Strategy{ public: void execute(Context* c); }; class Strategy2: public Strategy{ public: void execute(Context* c); }; class Context{ public: int Counter=10; Strategy* strategy; Context(Strategy* s):strategy(s){} void execute(); void ChangeStrategy(Strategy* s); }; inline void Context::execute(){ strategy->execute(this); } inline void Context::ChangeStrategy(Strategy* s){ strategy = s; } void Strategy1::execute(Context* c){ cout<<"Calling strategy#1"<Counter += 1; } void Strategy2::execute(Context* c){ cout<<"Calling strategy#2"<Counter -= 1; } static Strategy1 strategy1; static Strategy2 strategy2; int main(){ Context context(&strategy1); cout<<"1:"<