Cześć. Mam taki kod
#include <memory>
#include <vector>
using namespace std;
void write(vector<int>& tab)
{
shared_ptr<int> p (&(tab[1]);
cout << *p;
}
int main()
{
vector<int> tab;
tab.push_back(10);
tab.push_back(30);
tab.push_back(20);
write(tab);
cout << tab[1];
return 0;
}
Coś się psuje gdy funkcja write() się już wykona.(vector traci wszystkie wartości jego elementów).