title: constructor and templates
body: <p>I was going through this piece of code where I came across a while calling this code from main</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  class abc
  {
  public:
  enum example
  {
  a=1,
  b=2,
  c=3,
  d=4
  };
  };
  
  template&lt;typename T&gt;
  class xyz
  {
  public:
  xyz(T &amp;v,abc::example ex=abc::a):b(v),len(sizeof(T))
  {
  }
  
  protected:
  T &amp;b;
  int len;
  };
  
  #define Buffer_length 1024
  
  template&lt;typename T&gt;
  class demo
  {
  public:
  demo(T &amp;v):b(v)
  {
  length=v.size();
  cout&lt;&lt;"length:"&lt;&lt;length&lt;&lt;endl;
  typename T::size_type i=0;
  for(;i&lt;length;++i)
  {
  *(Buffer+i)=v[i];
  }
  }
  
  protected:
  typename T::size_type length;
  typename T::value_type Buffer[Buffer_length];
  T &amp;b;
  };
  </code></pre>
  
  <p>Well I am not sure whether this is the correct way of calling the constructor"demo", however when I tried like this:</p>
  
  <pre><code>int main()
  {
  string str="Hello world";
  xyz&lt;string&gt; obj1(str,abc::example::a);
  demo&lt;xyz&gt; obj2(obj1);
  }
  </code></pre>
  
  <p>I got the following error:</p>
  
  <pre><code>In function 'int main()':
  58:9: error: type/value mismatch at argument 1 in template parameter list    for 'template&lt;class T&gt; class demo'
  58:9: error:   expected a type, got 'xyz'
  58:15: error: invalid type in declaration before '(' token
  58:20: error: cannot convert 'xyz&lt;std::basic_string&lt;char&gt; &gt;' to 'int' in  initialization
  58:11: warning: unused variable 'obj2' [-Wunused-variable]
  </code></pre>
  
  <p>I would like to know how to call the constructor demo.</p>