@Lindley
I am stunned by your ability to explain these things to me. For your willingness to do so the english language lacks an adequate expression of gratitude.
Seeing you now as the morally and intellectually superior beeing that you are I feel bad to continue asking you these questions but:
Quote:
Since you have two pointers to work with, things get slightly more complicated----if the second "new" fails, you still have to release the memory from the first one. (The new that threw an exception did not, by definition, allocate anything.)
So I would simply need two temporary pointers?
please feel free not to answer this question as I will in fact use my filthy peasant-solution regardless. A filthy peasant-solution that I wouldnt have if it wasnt for you.
Quote:
Like most variables, pointers can be reassigned and used for a completely different purpose later. (The only exceptions are references and const variables.) That said, keep in mind that there is a difference between pointing name1 to a string "silver" instead, versus assigning the string "silver" into the memory pointed to by name1. In the latter case, you'll need to make sure there's enough memory available for the new string first. Also in the latter case, it will only do what you expect if the product type is saving a copy of the string rather than the pointer itself. In this case it is, so it's fine.
Quote:
In the latter case, you'll need to make sure there's enough memory available for the new string first
but it will overwrite that memory right? if I allocated 6 chars for "silver" and then put "gold" in it Im good and dont have to use delete and new or do i?
Quote:
Also in the latter case, it will only do what you expect if the product type is saving a copy of the string rather than the pointer itself. In this case it is, so it's fine
it is because of your strcpy correct?
@all the others
You are probably right
I am definitely wrong
I will still try to learn all I can from this first program I wrote for I am the evil that must exist to balance the good that came into the world with Lindley