Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, the code that you posted cannot compile because of this line: </p> <pre><code>public: vector&lt;T&gt; vector; //maybe i should not initalize this </code></pre> <p>you should see this error: </p> <pre><code> declaration of ‘std::vector&lt;T, std::allocator&lt;_Tp1&gt; &gt; ArithmeticVector&lt;T&gt;::vector’ /usr/include/c++/4.4/bits/stl_vector.h:171: error: changes meaning of ‘vector’ from ‘class std::vector&lt;T, std::allocator&lt;_Tp1&gt; &gt;’ </code></pre> <p>because you are introducing the whole std namespace above the class template declaration which makes the name "vector" visible, and then you use it to declare an object. That's like writing "double double;". </p> <blockquote> <p>What i want is creating v9 vector or v1 vector just like STL vector type.</p> </blockquote> <p>If this is what you want, here is the code that does it: </p> <pre><code>#include &lt;vector&gt; #include &lt;memory&gt; template &lt; class Type &gt; class ArithmeticVector : public std::vector&lt;Type, std::allocator&lt;Type&gt; &gt; { public: ArithmeticVector() : std::vector&lt;Type&gt;() {} // Your constructor takes Type for an argument here, which is wrong: // any type T that is not convertible to std::vector&lt;Type&gt;::size_type // will fail at this point in your code; ArithmeticVector (T n) ArithmeticVector(typename std::vector&lt;Type&gt;::size_type t) : std::vector&lt;Type&gt;(t) {} template&lt;typename Iterator&gt; ArithmeticVector(Iterator begin, Iterator end) : std::vector&lt;Type&gt;(begin, end) {} }; int main(int argc, const char *argv[]) { ArithmeticVector&lt;double&gt; aVec (3); return 0; } </code></pre> <p>If you are interested in arithmetic operations on vectors which are different than the algorithms defined in STL (accumulate, etc), instead of concentrating on the vector class and adding member functions, you can consider writing generic algorithms for vectors that expect specific vector Concepts in stead. Then you don't have to think about inheritance at all, and your generic algorithms can work on different Concepts of a vector.</p>
    singulars
    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.
    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