S
Schizoid Man
Hi,
I have defined a very simple class as follows. I initialize the
CInventory object as: CInventory *itemInveotry;
The program just performs two functions - it reads the total number of
items and values of itemNumber, quantity and cost per item from the
user, and it prints these values back.
While printing these values, I get a _CrtIsValidHeapPointer(pUserData)
exception if I use a statement like:
for (int i = 1; i <= numItems; i++)
(itemInventory + i)->printItem();
However, if I modify the for statement to the one below, the program
works perfectly.
for (int i = 0; i <= numItems - 1; i++)
(itemInventory + i)->printItem();
Can anyone tell me why the same program works fine for one for loop, but
not for the other (equivalent?) for loop?
When the application does fail I get the following error right before
the _CrtIsValidHeapPointer:
HEAP CORRUPTION DETECTED: after Normal block (#143) CRT Detected
application wrote to memory after end of heap buffer
Thanks in advance,
Schiz
class CInventory {
private:
int itemNumber; // holder the item's item number
int quantity; // in-stock item quantity
double cost; // storage cost per item
double totalCost; // total inventory cost
public:
// set the input info for each item
void setItem(int, int, double);
// print the item info
void printItem(void);
};
I have defined a very simple class as follows. I initialize the
CInventory object as: CInventory *itemInveotry;
The program just performs two functions - it reads the total number of
items and values of itemNumber, quantity and cost per item from the
user, and it prints these values back.
While printing these values, I get a _CrtIsValidHeapPointer(pUserData)
exception if I use a statement like:
for (int i = 1; i <= numItems; i++)
(itemInventory + i)->printItem();
However, if I modify the for statement to the one below, the program
works perfectly.
for (int i = 0; i <= numItems - 1; i++)
(itemInventory + i)->printItem();
Can anyone tell me why the same program works fine for one for loop, but
not for the other (equivalent?) for loop?
When the application does fail I get the following error right before
the _CrtIsValidHeapPointer:
HEAP CORRUPTION DETECTED: after Normal block (#143) CRT Detected
application wrote to memory after end of heap buffer
Thanks in advance,
Schiz
class CInventory {
private:
int itemNumber; // holder the item's item number
int quantity; // in-stock item quantity
double cost; // storage cost per item
double totalCost; // total inventory cost
public:
// set the input info for each item
void setItem(int, int, double);
// print the item info
void printItem(void);
};