Introduction
This is a variant of the solution posted at State pattern + C++ templatehere, without state creation/destruction penalty. It is also posted as an answer to that question, but @Jamal pointed out that it really was a question in its own right. Since I always blindly obey to people who have a higher reputation than mine, here it comes.
Note that my comment in the original question about the simplification provided by C++11's inherited constructors applies here too, but I have not updated the code in this question accordingly. That is left as an exercise to the reader :-).
The variant
The variant
Anyway, here comes the variant. Please comment on this.
genericstate.hgenericstate.h
machine.hmachine.h
machine.cppmachine.cpp
Introduction
This is a variant of the solution posted at State pattern + C++ template, without state creation/destruction penalty. It is also posted as an answer to that question, but @Jamal pointed out that it really was a question in its own right. Since I always blindly obey to people who have a higher reputation than mine, here it comes.
Note that my comment in the original question about the simplification provided by C++11's inherited constructors applies here too, but I have not updated the code in this question accordingly. That is left as an exercise to the reader :-).
The variant
Anyway, here comes the variant. Please comment.
genericstate.h
machine.h
machine.cpp
This is a variant of the solution posted here, without state creation/destruction penalty.
Note that my comment in the original question about the simplification provided by C++11's inherited constructors applies here too, but I have not updated the code in this question accordingly. That is left as an exercise to the reader.
The variant
Please comment on this.
genericstate.h
machine.h
machine.cpp
Note that my comment in the original question about the simplification provided by C++11's inherited constructors applies here too, but I have not updated the code in this question correspondinglyaccordingly. That is left as an exercise to the reader :-).
Note that my comment in the original question about the simplification provided by C++11's inherited constructors applies here too, but I have not updated the code in this question correspondingly. That is left as an exercise to the reader :-).
Note that my comment in the original question about the simplification provided by C++11's inherited constructors applies here too, but I have not updated the code in this question accordingly. That is left as an exercise to the reader :-).