using namespace std;
vector<int> build_vector(void)
{
vector<int> result;
result.push_back(1);
return result;
}
int main(void)
{
auto V = build_vector();
// V should be broken but isn't !
for (auto vv : V) cout << vv ;
}
Isn't result allocated on stack and thus should be destroyed right upon
scope's "}" ? I distinctly recall getting compiler warnings and nasty memory
errors, so I got into habit of always using heap when returning anything
non-trivial, yet I lately see stuff like the snippet above in legitimate
authors ...
Thank you in advance !
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--- news://
freenews.netfront.net/ - complaints:
ne...@netfront.net ---