title: Do templates have scope or scope like thing
body: <p>i have tried to create a class template <code>array</code> that would accept accept arbitrary boundaries like 50 to 60, 100 to 200</p>
  
  <p>I am new to programming and I have a layman question whether templates have scope. I tried to compile the program below</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;exception&gt;
  
  using namespace std;
  
  template&lt;typename t&gt;
  class array
  {
  private:
      size_t size;
      int lowerbound, upperbound;
      vector&lt;t&gt; data;
  public:
      array(int , int );
      array(const array&lt;t&gt; &amp;);
      int operator [](int );
  };
  template&lt;typename t&gt;
  array&lt;t&gt;::array(int lbound, int rbound): 
      lowerbound(lbound), upperbound(rbound), size(upperbound - lowerbound + 1), data(size)
  {
  
  }
  
  array&lt;t&gt;::array(const array&lt;t&gt; &amp; c): 
      lowerbound(c.lowerbound), upperbound(c.upperbound), size(c.size)
  {
      data.reserve(size);
  }
  
  int array&lt;t&gt;::operator[](int index)
  {
      if (index &lt; lowerbound || index &gt; upperbound)cout &lt;&lt; "fuck" &lt;&lt; endl;
      else
          return data[index - lowerbound];
  }
  </code></pre>
  
  <p>in copy constructor <code>array&lt;T&gt;::array(const array &lt;T&gt; &amp;C)</code> it says </p>
  
  <blockquote>
    <p>t is undeclared..</p>
  </blockquote>
  
  <p>I thought as I already declared <code>template &lt;typename t&gt;</code> at very start there is no need for additional <code>template&lt;typename t&gt;</code></p>
  
  <p>Here are the questions I have</p>
  
  <ol>
  <li><p>Do templates have scope or scope like thing</p></li>
  <li><p>If so, while defining member functions of class template outside class scope we have to declare so many <code>template &lt;typename t&gt;</code> definitions or is there any better alternative</p></li>
  <li><p>This might be unrelated to templates; how do I specify size of vector or array at runtime like variable length arrays (VLAs) in c99. For example <code>v.reseve(n)</code> where <code>n</code> is known at runtime.</p></li>
  </ol>