I am new here :) I found it impossible to send a reference type to a class through a constructor function and then get a reference to this reference for later use throughout the class. Maybe someone can help me to get my head around this.
I' am trying the following constructor:
1 2 3 4 5 6 7 8
vector<Employee> * directReports;
Manager::Manager(vector<Employee> & valDirectReports)
{
directReports = valDirectReports;
Staff me("Add me to staff vector");
directReports.push_back(me);
}
I call the constructor like this:
1 2
vector<Employee> staffVector;
Manager * aManager = new Manager(staffVector);
However, if I later return the vector (printObject exists and works):
1 2 3 4 5
for(unsignedint i=0; i < staffVector.size();i++)
{
cout << "I see :" << endl;
staffVector[i].printObject();
}
I end up without the vector modification done in the Manager::Manager(...) constructor. I found to get the desired effect if I use valDirectReports directly and push_back() on it. Unfortunately valDirectReports is not available to other members of the Manager class.
What I need is a way to have the reference passed through valDirectReports be available to other class members. Does anyone have a good idea on how to accomplish this?