dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Search:

Type: Posts; User: Paul McKenzie

Search: Search took 0.08 seconds.

  1. Re: Memory Management : character arrays and = operator

    I think this thread basically lays out all of the mistakes that beginners make when creating a copy constructor and assignment op, especially for things like a string class.

    The problem is that...
  2. Re: Memory Management : character arrays and = operator

    You're right, but you know that once the assignment operator is "corrected", you'll more than likely see the same error.

    Regards,

    Paul McKenzie
  3. Re: Memory Management : character arrays and = operator

    String& String::operator= (const String& right)
    {
    int n = right.length();
    for (int i = 0; i <= n; i++)
    buffer[i] = right.buffer[i];
    return *this;
    }
    And what if the destination buffer...
  4. Re: Memory Management : character arrays and = operator

    In addition to all of that was stated, what happens if new[] fails here?


    buffer = new char[len+1];

    If new[] fails, you now have messed up your string contents (and is especially a problem...
Results 1 to 4 of 4


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)


×
By using this site, you agree to the Privacy Policy