CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Threaded View

  1. #9
    Join Date
    Nov 2002
    Location
    Devon, UK
    Posts
    212
    First, I'd use initialisations instead of code body, e.g.
    Code:
    ArrayD::ArrayD()
    : size(0),
      data(NULL)
    {
    }
    // etc
    Although you won't notice it on consturctors of this size, it's good practice and for complex classes you might notice a performance gain.

    Also, I think you need to check that the array has been allocated in the destuctor before delete'ing it:
    Code:
    ArrayD::~ArrayD()
    {
        if (data)
            delete [] data;
    }
    Lastly, you don't need to specifiy the scope of your variables inside the class's body - so constructor 3 could become
    Code:
    ArrayD::ArrayD(int nSize, const double* pData)
    :   size(nSize),
        data(new double[nSize])
    {
        // constructor 3:
        if (data)
        {
            for (int i = 0; i < nSize; i++)	
                data[i] = pData[i];
        }
    }
    Toot
    Last edited by Toot; April 27th, 2004 at 04:24 AM.
    Some cause happiness wherever they go; others, whenever they go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured