Ok, I have the following code:
Now then, this code should (from my test application) print out zero, add the assignment passed to the function to a vector of assignments, and then prinout the size again. This works great.
void student::add_assignment(assignment *hw)
std::cout<<"Size of assignment vector right now:"<<this->homework.size()<<"\n";
std::cout<<"Size of assignment vector now:";
However, in another call to homework.size(), which is called directly after the above code is called, homework is reported as being of size 0 (that is, homework.size() returns 0), and thus creates an abnormal program termination after trying to return the assignment at the position passed to the function.
Here is that code:
In other words: at the end of the first function, the vector homework is of size 1 (that is, it has one element in it). However, at the beginning of the second function, it is reported to be of size 0, and thus always returns the temp assignment created in it.
assignment student::get_assignment(const int a)
std::cout<<"Size of assignment vector is:";
assignment *temp = new assignment(0,true,'a',22);
if(a > homework.size() || homework.empty())
Basicly, I want to know why the first function doesn't add the element to the vector for the variable that holds the vector.
Here is how the code is called:
Any ideas? If you need any more of the code just ask for it.
using namespace std;
course *asdf = new course("asdf", 1, "me");
int main(int argc, char *argv)
student *xyz = new student();
asdf->get_student(0).add_assignment(new assignment(90505, true, 'a', 0));
long g = asdf->get_student(0).get_assignment(0).get_duedate();