Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understood you corretcly, you are looking for something like this. Note, I made some simple constructor just to illustrate that it works. Also, your <code>class A</code> is mine <code>class TWrapperBase</code>, <code>B</code> - <code>TWrapperB</code>, <code>C</code> - <code>TWrapperC</code>. Another thing, you don't really need to have two derived classes for this particular example, but I assume your classes <code>B</code> and <code>C</code> are significantly different to justify it in your program.</p> <p>EDIT: Forgot to increment lIterSet in the loop.</p> <pre><code>#include &lt;vector&gt; #include &lt;set&gt; #include &lt;iostream&gt; template&lt; typename PType, typename PContainer &gt; class TWrapperBase { public: typedef PType TType; typedef PContainer TContainer; typedef typename TContainer::iterator TIterator; protected: TContainer mContainer; public: TWrapperBase( const TContainer&amp; pOriginal ) : mContainer( pOriginal ) { } TIterator begin( void ) { return mContainer.begin(); } TIterator end( void ) { return mContainer.end(); } }; template&lt; typename PType, class PContainer = std::vector&lt; PType &gt; &gt; class TWrapperB : public TWrapperBase&lt; PType, PContainer &gt; { public: TWrapperB( const TContainer&amp; pOriginal ) : TWrapperBase( pOriginal ) { } }; template&lt; typename PType, class PContainer = std::set&lt; PType &gt; &gt; class TWrapperC : public TWrapperBase&lt; PType, PContainer &gt; { public: TWrapperC( const TContainer&amp; pOriginal ) : TWrapperBase( pOriginal ) { } }; int main( void ) { int lInit[] = { 1, 2, 3 }; std::vector&lt; int &gt; lVec( lInit, lInit + 3 ); std::set&lt; int &gt; lSet( lInit, lInit + 3 ); TWrapperB&lt; int &gt; lB( lVec ); TWrapperC&lt; int &gt; lC( lSet ); std::vector&lt; int &gt;::iterator lIterVec = lB.begin(); std::set&lt; int &gt;::iterator lIterSet = lC.begin(); while( lIterVec &lt; lB.end() ) { std::cout &lt;&lt; "vector: " &lt;&lt; *lIterVec &lt;&lt; " / set: " &lt;&lt; *lIterSet &lt;&lt; std::endl; lIterVec++; lIterSet++; } return 0; } </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