title: delcaring an object and initializing using a char* in c++
body: <p>I am a c++ beginner and i have trouble compiling the following code 
  the problem is in the statement <code>T a = s</code> where <code>s</code> is a <code>char*</code> containing <code>abcde</code>.</p>
  
  <p>The goal here is to declare an object of <code>T</code> and initializing it with <code>s</code>. </p>
  
  <p>I also have trouble in this line <code>for(int i = 0; i &lt; a(); i++)</code>.</p>
  
  <p>I don't know how can i use a constructor or a function named  <code>a()</code> to return the size.</p>
  
  <p>This my code : </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cassert&gt;
  using namespace std;
  class T{
      int nb ;
      char *pc;
  public:
      T(int);
      ~T();
      T(T&amp;);
      char&amp; operator[](int);
  
      T(const char* s){
          int n ;
          for(int i = 0 ; s[i] != '\0' ;i++ ) n++ ;
          nb = n ;
          pc= new char[nb];
          for(int i=0 ; i &lt; nb ; i++) pc[i] = s[i];
      }
  
  
  };
  
  
      T::T(int k){
          assert(k &gt; 0);
          nb = k;
          pc = new char[nb];
      }
      T ::~T(){
          if( pc != NULL) delete [] pc;
      }
      T::T(T&amp; t){
          nb=t.nb;
          delete[] pc;
          pc = new char[nb];
          for(int i=0 ; i &lt; nb ; i++) pc[i] = t.pc[i];
      }
      char&amp; T::operator[](int index){
          assert(index &gt;=0 &amp;&amp; index &lt;= nb);
          return pc[index];
      }
  
  
  
  int main(){
      char* s = "abcde";
      T a = s;
      for(int i = 0; i &lt; a(); i++)
          cout &lt;&lt; a[i] &lt;&lt; " ";
      cout &lt;&lt; endl;
      T b = a;
      b[1] = '*';
      b[3] = '*';
      for(int i = 0; i &lt; b(); i++)
      cout &lt;&lt; b[i] &lt;&lt; " ";
      cout &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>i get the following error  :</p>
  
  <p>invalid initialization of non-const reference of type 'T&amp;' from an rvalue of type 'T'|</p>