On Nov 20, 12:41*am, Paavo Helde <pa...@nospam.please.org> wrote:
> Prasad <prasadmpa...@gmail.com> kirjutas:
>
>
>
> > On Nov 19, 8:06*pm, Andrey Tarasevich <andreytarasev...@hotmail.com>
> > wrote:
> >> Prasad wrote:
> >> > getGroupSetTemplates() returns a class member. Is that a problem?
>
> >> What does "returns a class member" mean? Does it return a copy of a
> >> class member? Or does it return a reference to a class member? It is a
> >> problem if the former is true.
>
> > I was able to fix the problem.
> > //Original code
> > vector<GroupSetTemplates> getGroupSetTemplates()
> > {
> > return this->groupSetTemplates;
> > }
>
> > //Fixed code
> > vector<GroupSetTemplates>& getGroupSetTemplates()
> > {
> > return this->groupSetTemplates;
> > }
>
> > My understanding of this is
> > 1. Initially a copy of groupSetTemplates was being returned. I was
> > getting an error because I was creating an iterator over returned
> > copy.
>
> The problem was that you returned two copies of groupSetTemplates, and
> you were attempting to iterate from the beginning of the first to the end
> of the second.
>
> > 2. I am returning a reference of groupSetTemplates. A copy of the
> > reference is returned which still points to original groupSetTemplate
> > and hence my code works fine.
>
> > Is this understanding correct?
>
> Basically yes, this is what Andray has tried to talk you.
>
> Terminological note: usually one does not talk about a "copy of a
> reference" (though there might be some copying of bits involved in the
> CPU level, but this is irrelevant). If the function returns a reference,
> it just returns a reference.
>
> Paavo
Thanks Paavo and Andray