First, I'd use initialisations instead of code body, e.g.
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.Code:ArrayD::ArrayD() : size(0), data(NULL) { } // etc
Also, I think you need to check that the array has been allocated in the destuctor before delete'ing it:
Lastly, you don't need to specifiy the scope of your variables inside the class's body - so constructor 3 could becomeCode:ArrayD::~ArrayD() { if (data) delete [] data; }
TootCode: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]; } }




Reply With Quote