Given this piece of code:
#include
(void) someFunction(void) {
list l;
l.push_back(1);
}
You could do it this way (as long as I understand your problem)
#include
#include
using namespace std;
list & fun()
{
list & temp = *(new list);
temp.push_back(4);
// you can do other operations on the list
return temp; // you pass the reference, any list will not be destroyed neither copied.
}
int main()
{
list & my_list = fun();
cout << *(my_list.begin()) << endl;
}