|
I'm writing a String class, but I find I'm having trouble allocating memory. It contains two member variables, m_Length (int; the length of the string, not including the null at the end) and m_Char (* char to the contained string)
Upon debugging, I find that the same memory location is set to m_Char everytime for every instance of the class. Obviously this is a huge problem because every string I create points to the same string.
This is the function I created to allocate memory
void zString::Alloc(const unsigned int & Bytes)
{
if (m_Length) delete [] m_Char;
if (Bytes)
{
m_Char = new char[Bytes+1];
for(int i=0; i<=Bytes + 1; i++)
m_Char = '\0';
}
m_Length = Bytes;
}
|
|
|
|
|
|
|
|