I am having trouble with this problem, I get an error "Invalid address specified to RtlValidateHeap", although the program works as intended it just shows that error at the end. Below I have my constructor for my class which holds an array, I think the "list = new Customer" is where my problem is but I can't figure out how to make it work. Could somebody please point me in the right direction? Please let me know if I need to post more code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Stack::Stack(char* name, char* email)
{
size = 0;
list = new Customer;
int len = strlen(name) + 1;
list[0].contactName = newchar[len];
strcpy(list[0].contactName, name);
len = strlen(email) + 1;
list[0].emailAddress = newchar[len];
strcpy(list[0].emailAddress, email);
size++;
}
this being the constructor (sorry about earlier) I think the bug is elsewhere.
you have a minor oddity: size = 0 and ++ ... set size = 1 or 0, whichever you expect it to be after construction.
try running in your debugger to see exactly where it blows up, use the call stack to get back to your code if it is dying in a compiler provided file.
Name of class, "Stack", hints that this object might contain "a stack of Customers". That is "more than one". However, you do initialize it with data for only one Customer and you do create a Customer, not an array that has one Customer.
If everything else in Stack assumes that list points to an array, then of course things will (hopefully) crash and burn.