Why does it work
Posted
by A-ha
on Stack Overflow
See other posts from Stack Overflow
or by A-ha
Published on 2010-06-17T08:47:18Z
Indexed on
2010/06/17
8:53 UTC
Read the original article
Hit count: 291
c++
|references
Guys I've asked few days ago a question and didn't have really time to check it and think about it, but now I've tried one of the solutions and I can't understand why does it work? I mean why destructor is called at the end of line like this:
#include "stdafx.h"
#include "coutn.h"
#define coutn coutn()
int _tmain(int argc, _TCHAR* argv[])
{
coutn << "Line one " << 1;//WHY DTOR IS CALLED HERE
coutn << "Line two " << " and some text.";
return 0;
}
I assume that it has something to do with lifetime of an object but I'm not sure what and how. As I think of it there are two unnamed objects created but they do not go out of scope so I can't understand for what reason is dtor called.
Thank you.
© Stack Overflow or respective owner