C
Curt Larsson
Hi
Can I return a vector from a funktion ?
Like:
std::vector<int> foo();
mvh
Curt
Can I return a vector from a funktion ?
Like:
std::vector<int> foo();
mvh
Curt
Curt Larsson said:Hi
Can I return a vector from a funktion ?
Like:
std::vector<int> foo();
mvh
Curt
..oO LGV Oo. said:sure, but since the copy ctor from the vector class will be called, beware
when you're handling a vector of pointers...
and have the function foo() construct the object directly.
yep, in the case of the "return optimization", which is :
instead of writing something like :
Object foo()
{
Object o(params);
return o;
}
you write :
Object foo()
{
return Object(params);
}
in the last case, the instance of Object is direcly build as the return
value, so, no copy constructor is called.
..oO LGV Oo. said:[SNIP]I thought the compiler was free to optimize away the copy constructor
and have the function foo() construct the object directly.
in the last case, the instance of Object is direcly build as the
return value, so, no copy constructor is called.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.