Topic: current std rules? is below legal in the most recent std?


Author: "puzzlecracker" <ironsel2000@gmail.com>
Date: 12 Jul 2005 01:40:08 GMT
Raw View
is it possible to call nonconst member function on an unnamed temprary?

ex:
class String{
public:
     void doSomething();

};

String createString();
createString().doSomething();

 is it ok?

thanks.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Wallking" <zlovey@gmail.com>
Date: Tue, 12 Jul 2005 12:00:45 CST
Raw View
It's OK

Because the unnamed temprary returned by "createString" is destroyed at
the end of the full expression. It's no mean that the unamed temporary
object is constant. So the temporary on the full expression does't go
out of scope and you can do anything with it.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: v.Abazarov@comAcast.net (Victor Bazarov)
Date: Tue, 12 Jul 2005 18:17:01 GMT
Raw View
puzzlecracker wrote:
> is it possible to call nonconst member function on an unnamed temprary?

Yes.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]