Z
zhou
Hi there,
I am expecting that the following assignment will invoke assignment operator on vector (since myFunc() returns a const
vector & type), which makes a copy of the vector returned from myFunc():
vector<myObj*> anotherVec = myFunc();
const vector<myObj *>& myFunc()
{
vector <myObj *> localVec;
// add objects into localVec
return localVec;
}
However, my understanding is that assignment operator takes const Object& type. However, the assignment operator on
vector is not invoked here and therefore vector is not copied. Am I missing anything?
Thanks.
Yan
I am expecting that the following assignment will invoke assignment operator on vector (since myFunc() returns a const
vector & type), which makes a copy of the vector returned from myFunc():
vector<myObj*> anotherVec = myFunc();
const vector<myObj *>& myFunc()
{
vector <myObj *> localVec;
// add objects into localVec
return localVec;
}
However, my understanding is that assignment operator takes const Object& type. However, the assignment operator on
vector is not invoked here and therefore vector is not copied. Am I missing anything?
Thanks.
Yan