I am curious about both, a h single and multi-threaded implementation.
Thanks
I am curious about both, a h single and multi-threaded implementation.
Thanks
If you have a copy of Effective C++ (3rd Edition) sitting around, Scott Meyers gives a nice treatment of the NVI idiom in Item 35 (page 170).
class base
{
public:
void bar()
{
getReady();
barImpl();
cleanup();
}
void getReady() {cout << "Getting ready. ";}
void cleanup() {cout << "Cleaning up.\n";}
protected:
virtual void barImpl() {cout << "base::barImpl. ";}
}
class derived : public base
{
protected:
virtual void barImpl() {cout << "derived::barImpl. ";}
}
int main()
{
base b;
derived d;
b.bar();
d.bar();
}
Output:
Getting ready. base::barImpl. Cleaning up. Getting ready. derived::barImpl. Cleaning up.
Your question is vague, but it sounds like you want the Curiously recurring template pattern
There are a lot better people than I to explain this on the web it is used a lot in the boost library. check out boost.iterator documentation and code for a good example