Hi,
As far as I can tell, you are producing a deep copy of the vector. As
Matheus pointed out, you should return copia, or have your function fill a
vector passed by the caller.
Apart from that, I can't see anything wrong. Maybe you should make sure you
really want to copy every Resultado object, if not, a shallow copy of the
vector would suffice ( copia->push_back(**it); )
HTH,
Jonathan
On 9/27/07, matheus ribeiro <mfr...@gm...> wrote:
>
> Uour code is very confusing, its not clear to me what youre doing.
> Anyway, this will cause a memory leak, since youll lose the pointer to
> copia and keep only the reference to it. Either return the allocated
> pointer or pass the vector as an argument to the function.
>
> 2007/9/27, Laura Lozano <lau...@gm...>:
> > Hello,
> >
> > Is this the best way to return a vector of Pointers that is an atribute
> of a
> > class?? I don't return the vector directly to avoid delete externaly the
> > pointers Resultado*, because is an attribute of the class.
> >
> > vector<Resultado*>& ValidacionCruzadaEval::getResultados(){
> > vector<Resultado*>::const_iterator it;
> > vector<Resultado*>* copia=new vector<Resultado*>;
> >
> > copia->reserve(resultados.size());
> >
> > for(it=resultados.begin();it!=resultados.end();it++){
> >
> > copia->push_back(new Resultado(**it));
> >
> > }
> > return *copia;
> >
> > }
> >
> >
> >
> >
> -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2005.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE:
> > http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
> >
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
--
<Morpheus> linux, c'est une question de VI ou de MORE
|