Results 1 to 4 of 4

Thread: Whats the meaning of code inside { } ? (No the { } of a function )

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Whats the meaning of code inside { } ? (No the { } of a function )

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Whats the meaning of code inside { } ? (No the { } of a function )

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Whats the meaning of code inside { } ? (No the { } of a function )

    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!

  4. #4
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Whats the meaning of code inside { } ? (No the { } of a function )

    Thanks.
    It is not easy to find this concept at most popular cpp web pages.

Similar Threads

  1. Replies: 1
    Last Post: 2nd June 2010, 16:14
  2. Changing a file extension inside the code
    By fortyhideout12 in forum Qt Programming
    Replies: 6
    Last Post: 19th February 2010, 21:20
  3. How to step inside(debug) webkit code?
    By nish in forum Qt Programming
    Replies: 5
    Last Post: 30th December 2009, 12:23
  4. special meaning of & symbol inside string
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 2nd February 2009, 07:19
  5. Replies: 2
    Last Post: 5th June 2008, 21:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.