Dynamically allocating character array in class in C++
<p>I'm trying to make my own string class, and I'm trying to create the constructor. So far I'm having a little struggle. </p>

<p>I have my function prototypes defined in a header file and the variable buffer defined in the header file like this <code>char *buffer;</code>, in a new cpp file I'm trying to define the constructor like this: </p>

<pre><code>mystring::mystring(const char *s)
{
    int counter = strlen(s)+1;
    *buffer = generate_c_array(counter);
}

char * mystring::generate_c_array(int size)
{
  return new char[size];
}
</code></pre>

<p>I'm basically trying to make it such that <code>buffer</code> is a char array of size <code>s+1</code> and contains the contents of <code>s</code> followed by a null terminator. Though, this is causing my program to crash.</p>

<p>I'm not sure how to assign buffer correctly, does this look correct?</p>