#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <iterator>
using namespace std;
struct Student
{
std::string Name;
int age;
};
vector<Student> GetStudents(int some_params)
{
vector<Student> students;
//logic where students are returned
Student s1 { "John", 42 };
Student s2 { "Bill", 12 };
students.push_back(s1);
students.push_back(s2);
return students;
}
int main()
{
map<int, vector<Student*>> m {};
{ //other class context in another file, map is passed by reference
int some_params = 5;
vector<Student> students = GetStudents(some_params);
for(auto i : students)
cout << i.Name << endl;
vector<Student*> tmpV;
for(auto & i : students)
tmpV.push_back( &i);
for(auto i : tmpV)
cout << i->Name << endl; //OK
m.emplace(some_params, tmpV);
for(const auto& elem : m)
{
for (auto i : elem.second)
cout << i->Name << endl; //OK
}
}
for(const auto& elem : m)
{
for (auto i : elem.second)
cout << i->Name << endl; //ERROR!
}
return 0;
}