Well, there are a few things wrong with your code. First off, your this qualifier is actually a IntArray*, not IntArray. So you are actually returning (according to your code) an address of an address. You actually want to return a *this, not &this , so it actually reurns the object.
Second, you actually want to return a reference to an object, not a copy, so your return value should be IntArray & operator...
Third, you must also check in the beginning of the function whether or not you are actually assigning to yourself, and if so, don't actually copy, just return yourself, like so..
Code:
IntArray & operator=(const IntArray& rhs) {
if (this != &rhs) {
// Check sizes, and reallocate
// Do copy
}
return *this
} Fourth, since your types of this and such were wrong to begin with, your size check must be changed as well, but I'll leave that up to you.
Fifth, make sure you deallocate your array before you reallocate it to another size, as this will cause a memory leak.
Sixth, why are you doing a new int[size] on the size variable of your class? I think that should be ptr = new int[rhs.size].
You shouldn't run into errors because you're only changing this, not rhs.
Just one more thing, you don't have to do &(*this).size, you can just do size == rhs.size.
Sorry if I am being harsh, I did not mean to be. For more help, just ask! I'd be glad to help more. If I haven't answered your question, then again, just ask! I might pick up on the actual question next time!
Ted Morse