Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This looks like a nice example of policy-based smart pointer implementation: <a href="http://axter.com/smartptr/classsmart__ptr.htm" rel="noreferrer">link</a>. <a href="http://en.wikipedia.org/wiki/Andrei_Alexandrescu" rel="noreferrer">Andrei Alexandrescu</a> describes policy-based smart pointer implementation in one of his books. As to your questions now. I have some experience in this stuff but not enough to take my words for granted:</p> <p>Ad 1 &amp; 4. I guess policy-based design is more about templates than inheritance. You write a template class and template arguments are policy classes, like that:</p> <pre><code>template&lt;class FooPolicy, class BarPolicy&gt; class Baz { // implementation goes here }; </code></pre> <p>Then you use methods from policy classes in your class:</p> <pre><code>void Baz::someMethod(int someArg) { FooPolicy::methodInit(); // some stuff BarPolicy::methodDone(); } </code></pre> <p>I use static methods in this example because often policy doesn't require any state. If it does, you incorporate policy's state by composition, not by inheritance:</p> <pre><code>template&lt;class FooPolicy, class BarPolicy&gt; class Baz { private: FooPolicy::State fooState; // might require 'typename' keyword, I didn't // actually tried this in any compiler // rest of the Baz class }; </code></pre> <p>Ad 2. You can write a template specialization - for a particular combination of main class and it's policies you can write a special version of any method or constructor, AFAIK:</p> <pre><code>template &lt;&gt; Baz&lt;SomeConcreteFooPolicy, SomeConcreteBazPolicy&gt;::Baz(someArgument) : fooState(someArgument) { // stuff here } </code></pre> <p>Hope it helps you a bit,</p> <p>Mike</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload