title: C++ class initialization with vector
body: <p>I have inherited some code that I am looking at extending, but I have come across a class\constructor that I have not seen before. Shown below in the code snippet</p>
  
  <pre><code>class A {
   public:
      A() {};
      ~A() {};
   //protected:
      int value_;
  
  class B: public std::vector&lt;A&gt; {
    public:
      B(int size = 0) :
        std::vector&lt;A&gt;(size)
      {}
  </code></pre>
  
  <p>So from what I gather <code>class B</code> is a vector of <code>class A</code> which can be accessed using the <code>*this</code> syntax because there is no variable name. I would like to initiate <code>class A</code> in the constructor, but I am unsure how to do this with in this context. I have looked at <a href="https://stackoverflow.com/questions/6142830/how-do-i-initialize-a-stl-vector-of-objects-who-themselves-have-non-trivial-cons">this</a> but they have declared the vector as an object where in this case it is the class.</p>
  
  <p>This seems slightly different from normal inheritance where I have inherited many instances of a single class, compared to the usual one to one in most text books. What I was trying to do, was propagate a value to intialise <code>class A</code> through both <code>class B</code> and <code>class A</code> constructor. Something like below is what I tried but doesn't compile.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  class A {
   public:
      A(int int_value) :
      value_(int_value)
      {};
      ~A() {};
   //protected:
      int value_;
  };
  
  class B: public vector&lt;A&gt; {
    public:
      B(int size = 0, int a_value) :
        vector&lt;A&gt;(size, A(a_value))
      {};
  
      vector&lt;int&gt; new_value_;
  
      void do_something() {
          for (auto&amp; element : *this)
              new_value_.push_back(element.value_);
      }
  };
  
  int main() {
      cout &lt;&lt; fixed;
      cout &lt;&lt; "!!!Begin!!!" &lt;&lt; endl;
      B b(20,23);
      cout &lt;&lt; b.size() &lt;&lt; endl;
  
      b.do_something();
      for(auto&amp; element : b.new_value_)
          cout &lt;&lt; element &lt;&lt; endl;
  
      cout &lt;&lt; "finished" &lt;&lt; endl;
      system("PAUSE");
      return 0;
  }
  </code></pre>
  
  <p>I guess a follow up question is, is this a good implementation of what this code is trying to achieve</p>