P
pmatos
Hi all,
I have a few question regarding standard C++ and the use of vectors.
Imagine:
void foo(vector<int> x);
vector<int> c;
vector<int> x;
----------
What happens when I do:
c = x;
and
foo(x);
Will it copy all x behind the scenes in both cases?
If so, then I wish this to be more efficient so I should probably pass
a reference right? How can I do this in both cases? In calling foo, how
can I make sure the body of foo won't try to change x? (probably const&
or &const, but I never know...)
Cheers,
Paulo Matos
I have a few question regarding standard C++ and the use of vectors.
Imagine:
void foo(vector<int> x);
vector<int> c;
vector<int> x;
----------
What happens when I do:
c = x;
and
foo(x);
Will it copy all x behind the scenes in both cases?
If so, then I wish this to be more efficient so I should probably pass
a reference right? How can I do this in both cases? In calling foo, how
can I make sure the body of foo won't try to change x? (probably const&
or &const, but I never know...)
Cheers,
Paulo Matos