-
December 19th, 2005, 05:12 AM
#1
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?
-
December 19th, 2005, 05:18 AM
#2
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;
}
-
December 19th, 2005, 05:22 AM
#3
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?
-
December 19th, 2005, 05:33 AM
#4
Re: std namespace
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 -
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...
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 05: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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|