Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
A policy is a class behaviour set at compile-time.
A policy consts of a host class and policy classes. The user of a policy chooses which policy class is used, by template.
A policy class is a base class. All base class destructors should be public and virtual, or protected and nonvirtual' [1]. The destructor of a policy class should be protected and nonvirtual [2].
During debugging, you might want to trace (keep track of) variables.
Sometimes, you might want to write it to std::cout, file or other ways.
The example below shows a Tracer class, whose behavior is set at compile-time.
#include <iostream> |
In this example, Tracer is the host class, where OutputPolicyCout and OutputPolicyFile are policy classes.
Note that p1 and p2 have types as different as std::vectors with different elements.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.