Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't think anyone's clear on your requirement, but this is my best guess at addressing it... illustrating how to handle what you're calling the "dependency chain" in a template solution. If this doesn't help, but has any relevancy, then explaining it and the problems would help people help you. If you want to apply algorithmic loops over the <code>Foo&lt;&gt;</code> objects I can illustrate how to do that....</p> <pre><code>#include &lt;iostream&gt; struct Abstract_Bar { virtual void f() const = 0; }; struct Bar1 : Abstract_Bar { void f() const { std::cout &lt;&lt; "Bar1\n"; } }; struct Bar2 : Abstract_Bar { void f() const { std::cout &lt;&lt; "Bar2\n"; } }; template &lt;int N&gt; struct Foo { typedef Foo&lt;N - 1&gt; Lower; typedef Foo&lt;N + 1&gt; Higher; void f() const { std::cout &lt;&lt; "Foo&lt;N&gt;\n"; } Higher* higher_; }; template &lt;&gt; struct Foo&lt;1&gt; { typedef Foo&lt;2&gt; Higher; void f() const { std::cout &lt;&lt; "Foo&lt;1&gt;\n"; } Higher* higher_; }; template &lt;&gt; struct Foo&lt;4&gt; { typedef Foo&lt;3&gt; Lower; typedef Abstract_Bar Higher; void f() const { std::cout &lt;&lt; "Foo&lt;4&gt;\n"; } Higher* higher_; }; int main() { Foo&lt;1&gt; foo1; Foo&lt;2&gt; foo2; Foo&lt;3&gt; foo3; Foo&lt;4&gt; foo4; foo1.higher_ = &amp;foo2; foo2.higher_ = &amp;foo3; foo3.higher_ = &amp;foo4; Bar1 bar1; foo4.higher_ = &amp;bar1; foo1.f(); foo2.f(); foo3.f(); foo4.f(); foo1.higher_-&gt;f(); foo2.higher_-&gt;f(); foo3.higher_-&gt;f(); foo4.higher_-&gt;f(); // switch to another type of "Bar"... Bar2 bar2; foo4.higher_ = &amp;bar2; foo4.higher_-&gt;f(); } </code></pre>
 

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