RETURN VECTOR FUNCTION STL

RETURN VECTOR FUNCTION STL

When a vector is returned …. the vector is copied to the variable that receive the result.

Local vector would go out of scope but it will not die as its copy has been already returned.

Wrong behavior is to return the reference if a local vector in that case local vector goes out of scope and can lead to memory issues

So since vector is returned which is inherently a class it will be a case when an object is returned by value which will call copy constructor and return the copied value.

[[code]]czo0MjA2OlwiPHNwYW4gY2xhc3M9XCJjb21cIj4jaW5jbHVkZTwvc3Bhbj4gPHNwYW4gY2xhc3M9XCJzdHJcIj4mbHQ7aW9zdHJlYW0mZ3Q7e1smKiZdfTwvc3Bhbj4NCjxzcGFuIGNsYXNzPVwia3dkXCI+Y2xhc3M8L3NwYW4+IDxzcGFuIGNsYXNzPVwidHlwXCI+TXlDbGFzczwvc3Bhbj4NCjxze1smKiZdfXBhbiBjbGFzcz1cInB1blwiPns8L3NwYW4+DQogIDxzcGFuIGNsYXNzPVwia3dkXCI+cHVibGljPC9zcGFuPjxzcGFuIGNsYXNzPVwicHVuXCJ7WyYqJl19Pjo8L3NwYW4+DQogICAgPHNwYW4gY2xhc3M9XCJ0eXBcIj5NeUNsYXNzPC9zcGFuPjxzcGFuIGNsYXNzPVwicHVuXCI+KCk8L3NwYW4+IDx7WyYqJl19c3BhbiBjbGFzcz1cInB1blwiPns8L3NwYW4+PHNwYW4gY2xhc3M9XCJwbG5cIj4gc3RkPC9zcGFuPjxzcGFuIGNsYXNzPVwicHVuXCI+Ojo8L3tbJiomXX1zcGFuPjxzcGFuIGNsYXNzPVwicGxuXCI+Y291dCA8L3NwYW4+PHNwYW4gY2xhc3M9XCJwdW5cIj4mbHQ7Jmx0Ozwvc3Bhbj4gPHNwYW4gY3tbJiomXX1sYXNzPVwic3RyXCI+XCJjb25zdHJ1Y3RvciBNeUNsYXNzOjpNeUNsYXNzKClcIjwvc3Bhbj4gPHNwYW4gY2xhc3M9XCJwdW5cIj4mbHQ7Jmx0e1smKiZdfTs8L3NwYW4+PHNwYW4gY2xhc3M9XCJwbG5cIj4gc3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