Hi, I have the following class and main method:
class Employee
{
vector<string> v;
string name;
int i;
public:
Employee(){}
Employee(string &n): name(n), i(0){}
void read(vector<string *> &vec)
{
string n;
for(int i = 0; i !=3; i++)
{
cin>>n;
Employee e(n);
vec.push_back(&n);
}
}
};
int main()
{
vector<string *> v;
Employee e;
e.read(v);
for(int i = 0; i !=v.size();++i)
{
cout<<"In the main method loop"<<endl;
cout<<*v[i]<<endl;
}
cout<<v.size()<<endl;
system("pause");
return 0;
}
Now upon trying to access the vector after I am back in the main method, the program crashes. Does anyone know why?
Many thanks