Im using this class in a larger function which isn't terminating properly.
I've had to resort to commenting out the algorithm one chunk at a time to narrow down where the problem is beginning.
The whole thing works as written but ultimately terminates in error and terminates the main()
that is calling it.
Anyways, when I instantiate this class, the problem begins. Im assuming it must be a problem with the destructor, causing the error when the object falls out of scope.
Here is the class definition as well as the constructor/destructor:
class Entry
{
private:
int act_count; //number of activities for generating array MUST BE DETERMINED BEFORE INSTANTIATION
int ex_count; //number of expenditures for generating array
public:
Entry(int, int); // constructor
~Entry(); // destructor
string date; // functions like a title
Activity * act_arr; // pointer to an array of activities
Expenditure * ex_arr; // pointer to an array of expenditures
// list of member functions
};
struct Activity
{
public:
string a_name;
float time;
};
struct Expenditure
{
public:
string e_name;
float price;
};
Constructor:
Entry::Entry(int a_count, int e_count)
{
// initialization of basic members
date = day_o_year();
act_count = a_count;
ex_count = e_count;
// allocation of array space
act_arr = new Activity[act_count];
ex_arr = new Expenditure[ex_count];
}
Destructor:
Entry::~Entry()
{
// prevents memory leaks when object falls out of scope and is destroyed
delete act_arr;
delete ex_arr;
}
Are there any egregious errors here? I hope this isn't too much code to pique some interest.
Thanks in advance.