PDA

View Full Version : Whats the meaning of code inside { } ? (No the { } of a function )



tonnot
18th October 2010, 17:03
I have observed this piece of code inside thread examples. I dont understand the meaning of these { } (who are neither beginning nor end of any function or proccess)

qDebug() << "warmup";
{
QTime time;
time.start();
WordCount total = singleThreadedWordCount(files);
}
....
Thanks

wysota
18th October 2010, 17:13
They mark beginning and end of an anonymous scope. "time" and "total" objects will be destroyed right after the scope ends instead of at the end of the function.

Lykurg
18th October 2010, 17:15
It only group things together, and all inside the brackets get deleted afterwards. It is called local scope. Google for that and you get further informations.

EDIT: too late!

tonnot
18th October 2010, 17:34
Thanks.
It is not easy to find this concept at most popular cpp web pages.