Hello,

[EMAIL PROTECTED] wrote:

> template <class output_functor>
> void do_loop(output_functor& o)
> {

> };
> 

> a_int.do_loop(output());
 
output() is a temporary default-constructed object, and do_loop expects
a non-const reference to an output object. Taking a non-const reference
of a temporary is formally not allowed, this is a FAQ. VC8 is probably
wrong to accept this. There are many occasions in the STL where
functors are passed by value instead of reference, most probably
because of that.

I think, in this case a compiler theoretically could find out that the
output object is almost const, it has no members to change. But still,
the rule had been introduced to avoid deep trouble due to lost changes
to temporary objects, which could be hellish to debug.

The following works:

...
  output o;
  a_int.do_loop(o);
...

That should do it as well, probably even better:

...
 template <class output_functor>
 void do_loop(output_functor o)
....

Regards,

Bernd Strieder
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to