Quote Originally Posted by oliveman View Post
Here is a class which produces the errors.
In addition to what CPUWizard points out, your code has other runtime errors. Also, you need to format your code a little better, since too much of it is not indented properly and is hard to read.

First, usage of std::vector eliminates the need for copy constructor and assignment operator. However, here is your mistake:
Code:
myClass::myClass(const myClass & original)
{
    int k=0;
    while (k<5)
    {
        ptr[k]=original.Read(k); // Error!  Invalid memory access 
        k++;
    }
}
See the line in red? It is wrong, since ptr was not allocated.

The fix to both the default and copy constructor is to make sure that ptr is allocated on initialization of the object. You would use the initializer list instead of allocating it within the constructor body.
Code:
myClass::myClass() : ptr(new int[5])
{ }

myClass::myClass(const myClass & original) : ptr(new int[5])
{
    k = 0;
    while (k<5)
    {
        ptr[k]=original.Read(k);
        k++;
    }
}
Regards,

Paul McKenzie