Results 1 to 4 of 4

Thread: Accessing anonymous namespaces?

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Accessing anonymous namespaces?

    Hi guys,

    I have this chunk of code:
    Qt Code:
    1. ...
    2. int x = 10; // global
    3.  
    4. void main() {
    5. int x = 20; (line A)
    6. {
    7. int x = 30;
    8. // How to read the value of x from the line A in this scope?
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    The question is in the code: How to read the value of x from the line A in this scope?
    Qt Code:
    1. cout << x ; // gives 30;
    2. cout<<::x; // give 10;
    To copy to clipboard, switch view to plain text mode 
    Thanks for any help

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing anonymous namespaces?

    You can't. The local scope overrides the function scope.

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Post Re: Accessing anonymous namespaces?

    Hi,

    The local scope overrides the function scope.
    I do know that. But are you 100% sure that the var from the function scope can't be accessed?

    Thanks,

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing anonymous namespaces?

    Yes, I am sure.

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.