Re: Temporary Object
Ian Collins wrote:
It's invalid because the standard says so!
In most cases, it makes little sense to perform non-const operations on
a temporary object.
Yeah, I also think that's the only reason why it's invalid, since you
could actually call a member function on a temporary object and the
function could pass itself as an argument to another function, which
could bypass this restriction (and that shows their should not be
Actually I saw this code from Crypto++ User's Guide by denis bider:
void DumpMessage(CryptoPP::BufferedTransformation& bt)
using namespace std;
static char const* szHexDigits = "0123456789abcdef";
throw "Error: AnyRetrievable() returned true, "
"so this shouldn't happen.";
// It is much easier to implement this using HexEncoder;
// however, let's not get into that just yet. The below code
// could do some special kind of processing that is not
// supported by an off-the-shelf Filter class.
cout << szHexDigits[(b >> 4) & 0x0f]
<< szHexDigits[b & 0x0f]
<< ' ';
using namespace CryptoPP;
char const* szMessage = "How do you do?";
// If we constructed StringSource with 'false' instead
// of 'true',
// StringSource wouldn't call its PumpAll() method on
// and no data would be extractable from the StringSource
// until someone called the object's Pump() or PumpAll()
That doesn't compile on my compiler, but it's on the tutorial anyway.
Probably the author's compiler does not follow the standard on this issue.