Here's what I declared:
Transaction* tran[10];
Where class Transaction has a default constructor that initializes all member attributes to 0, and constructor that takes in specific values. I compile the program just fine using Borland, but it crashes at run-time without giving me any error message. I have a feeling this has something to do with the default constructor initializing unused values in the heap, but I don't know how to deal with it (nor do I know how to debug the program to make sure this is the problem). What I do know is that when I don't used pointers my program runs fine.
Another thing: Later on in my program, I pass individual elements of that array to a server function that allocates memory for a new Transaction. Basically, I want any changes I make to the pointer in the server function to affect the pointer in my main(). Here's an small portion of my code:
void inputData(Transaction *(*tran))
{
*tran = new Transaction(a, b, c);
}
main()
{
...
inputData(&tran[1]);
...
}
I tried passing the pointer by reference but ended up with a compile error. My only choice therefore was to pass it by pointer. Is there an easier/better way to do this?
In case you're asking, I'm doing this so that memory is allocated as-needed (instead of declaring an array of 10 Transaction elements in the stack form the get-go). More specifically, though, I'm doing this because my prof asked me to do it, and it's due at 8:00 pm tonight. So I would really appreciate any help.
Edit: I removed the default constructor and it still crashes.
Transaction* tran[10];
Where class Transaction has a default constructor that initializes all member attributes to 0, and constructor that takes in specific values. I compile the program just fine using Borland, but it crashes at run-time without giving me any error message. I have a feeling this has something to do with the default constructor initializing unused values in the heap, but I don't know how to deal with it (nor do I know how to debug the program to make sure this is the problem). What I do know is that when I don't used pointers my program runs fine.
Another thing: Later on in my program, I pass individual elements of that array to a server function that allocates memory for a new Transaction. Basically, I want any changes I make to the pointer in the server function to affect the pointer in my main(). Here's an small portion of my code:
void inputData(Transaction *(*tran))
{
*tran = new Transaction(a, b, c);
}
main()
{
...
inputData(&tran[1]);
...
}
I tried passing the pointer by reference but ended up with a compile error. My only choice therefore was to pass it by pointer. Is there an easier/better way to do this?
In case you're asking, I'm doing this so that memory is allocated as-needed (instead of declaring an array of 10 Transaction elements in the stack form the get-go). More specifically, though, I'm doing this because my prof asked me to do it, and it's due at 8:00 pm tonight. So I would really appreciate any help.
Edit: I removed the default constructor and it still crashes.