std namespace
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: std namespace

  1. #1
    Join Date
    Nov 2004
    Posts
    20

    std namespace

    I have bought a book for C++ and in some examples has the following code:

    #include <cstdlib>
    using std::exit;

    int main()
    {
    .....exit(1);
    }

    I use Visual C++ 6 and when I compile this code it produces this error:
    "error C2039: 'exit' : is not a member of 'std' "

    When I delete " using std::exit",the source code is compiled without any errors.

    Why is that?Microsoft Visual C++ 6 defines in a different way the std namespace so as not to include exit?

  2. #2
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: std namespace

    You don't need to use exit here. In fact, one really doesn't need exit.

    Simply return.

    Code:
    int main ()
    {
         return 0;
    }

  3. #3
    Join Date
    Nov 2004
    Posts
    20

    Re: std namespace

    No,I need to use exit(1).It is used for program termination when a specific error occurs.

    What about the problem I initially stated?

  4. #4
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: std namespace

    Quote Originally Posted by asxetos
    No,I need to use exit(1).
    When an error occurs, return error, or throw an exception (caught by the caller who optionally returns). There is literally no case I can think of where one might need to rudely terminate an application using exit.

    Calling exit is a poor programming practise -
    Quote Originally Posted by MSDN
    When you call the exit or _exit functions, the destructors for any temporary or automatic objects that exist at the time of the call are not called.
    And...
    Quote Originally Posted by asxetos
    What about the problem I initially stated?
    What about it?

    EDIT: exit is a function inherited from C, and is a member of the standard namespace on my version of VC++ 8.0 -
    Code:
    #include <cstdlib>
    
    int main ()
    {
      std::exit (0);
    }
    Last edited by Siddhartha; December 19th, 2005 at 04:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center