I would like to understand what happens in the following code
struct A
{
vector<double> x;
};
void f(A &a)
{
vector<double> &y = a.x;
}
When the function f exits, is a.x destroyed? Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Remember that references are not objects.
yis a variable, but not an object. It is a reference to the existing objecta.x, but that object itself is not local to the scope off. So the variableygoes out of scope at the end off, but the object to which it refers does not.