Hello. I'm currently having issues with a program that has a pointer of type double as a private member data of a class. I took a snippet of the code and created a shorter example that has the same problem. Here are the files.
test1
test2
test3
Process returned -1073741819 (0xC0000005) execution time : 2.855 s
Press any key to continue.
When I create a point pointer and then use that to make a new point, everything seems to work fine (hence outputting test2). However, I'm having an issue with my pointptr class. Instead of having a double as the private data, I use a double pointer. I repeat what I did with the other class but my program crashes after outputting test 3 (test 4 isn't displayed). I tried deleting the pointer but that still doesn't work. Any help would be greatly appreciated!
Edit: I added a cout statement to my destructor in the pointptr class.
from what I can see you have never instantiated your pointer in the pointPtr class. Try the below, it should work for you - if it doesn't let me know...
You are a saint! Thank you so much. The code you gave me worked with the snippet and I could apply it to my program. Now I can finally move on.
As far as the rule of 3, am I missing one of them from my class? I know the "~pointPtr()" is the destructor. What is the name for the code you gave me? Is that the copy constructor?
Edit: I see that you used the word instantiate. I'll look up what exactly that means. Does instantiating a pointer (or object) take care of the copy constructor and assignment operator or are those two just absent from my code?
Not having a copy constructor/assignment operator are a different problem. Without them, the default one will preserve the pointer value of x. This is bad as then the first object to go out of scope will delete it, invalidating the second object's pointer.