Alf P. Steinbach wrote:[color=blue]
> *
PengYu.UT@gmail.com:[color=green]
> > I have the following program. The auto_ptr cause the compile error.
> > When I change auto_ptr to pointer, the error gone.
> >
> > Would you please help me to understand what is wrong?
> >
> > /*******************************************/
> > class iterator {
> > private:
> > std::auto_ptr<int> _iterator;
> > // int *_iterator;
> > };
> >
> > class collection {
> > public:
> > iterator begin() {
> > return iterator();[/color]
>
> 'iterator()' is a temporary. You can't bind a temporary to a reference
> to non-const. But the only copy constructor you have available has
> argument type 'iterator&', a reference to non-const (because that's the
> only one that can be generated that can handle the auto_ptr member), and
> so the compiler complains.
>
> You could do this like
>
> iterator begin()
> {
> iterator result;
> return result;
> }[/color]
The compilor reports error, too. Is there anything else wrong?
[color=blue]
>
> but having that auto_ptr in there is most probably a design error,
> because it seems to be 100% meaningless, and you would need to add
> additional support to make the function useful to client code.[/color]
This is just a mini example reduced from a rather long segment of code.
Do take it too serious?[color=blue]
>
> Do you really want an iterator refer to and own a dynamically allocated int?
>[color=green]
> > }
> > };[/color]
>
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?[/color]