A vector data that 'dissapears' between calls

I have this function


1
2
3
4
5
6
7
8
std::vector <vector<std::string> >  W_win::memories () {
    std::vector <vector<std::string> > provector;   
    cProcesses = 100;
    provector.resize(cProcesses);
    for (int i = 0; i < cProcesses; ++i)
    provector[i].resize(10);
return provector;
}


I also have
1
2
3
 void W_win::memory_use (std::vector <vector<string> > datamemori) {
    datamemori = memories();
    W_debug()<<"capacity 1"<<datamemori.capacity()<<"";

}

OK, I call memory_use from the main class in this way:

1
2
3
 std::vector <vector<std::string> > apps;
    W_win().memory_use(apps);
    W_debug()<<"capacity 2 "<<apps.capacity()<<"";


Ok, I have :
Capacity 1 = 45;
Capacity 2 = 0;

Can anyone help me ? What happens, I loose the vector data ....

I'm imagine is a question about pointers or references , isn't ?

Thanks



Last edited on
I'm imagine is a question about pointers or references , isn't ?
Yes. Your 'W_win::memory_use' takes a copy of your vector hence doesn't change it.

This reference
void W_win::memory_use (std::vector <vector<string> > &datamemori) { // Note the additionally &
allows to modify 'datamemori'
Ok, thanks.
And passing a pointer is faster ?
And passing a pointer is faster ?
No. A reference is actually a kind of pointer
Topic archived. No new replies allowed.