![]() |
_set_new_handler() problem header?
As i try to compile the program, there are some errors in it, stating that redefinition of class bad_alloc() the code is this
:
and then after that i tried to remove the code in line #8 and i tried compiling it again, but another error pops out...saying set_new_handler was not declared in this scope. i tried changing <new.h> to <new> but it still returns same error... does set_new_handler function still exists? cause i just copied the source from a book and the book was way back to 1996.... or I just included a wrong header file? or the function name has changed? thank you so much |
Re: _set_new_handler() problem header?
I can make an informed guess about the author of the book, but will not reveal that here. The main value of your book is in kilojoules that might be released by burning it.
In any event; 1) There is no header named <new.h> in the C++ standard. However, some pre-standard C++ compilers (produced while the standard was an evolving draft) do support such a header. And, in those headers, bad_alloc was not in namespace std. If you are using one of those old compilers (or some more recent ones that supply such headers for backward compatibility with code written targeting those older compilers) this will explain the ambiguity your compiler is reporting about bad_alloc. Essentially, you have a header declaring a type named bad_alloc and another redeclaring such a type in code. Technically, this is a violation of the One Definition Rule (ODR), so it is actually undefined behaviour. This means, if your compiler library has a header named <new.h> and it declares a bad_alloc type, then your compiler is neither correct nor incorrect in complaining about ambiguity. 2) There is no function named _set_new_hander() in the C++ standard, and never was in any drafts either. There is a function named std::set_new_handler() [ie in namespace std, and without the leading underscore] declared in the standard header <new>, and it is a function that accepts a pointer to a void function with no arguments (not a function accepting a size_t argument, as in your NewHandler() function). If your book is written using _set_new_handler(), then it is a book that was written with a specific compiler in mind ..... ie it is vendor specific. 3) There are several other types (status, SymbolTable, Function::Table, Store, ....) that are completely non-standard. Use of these without any declaration will make any standard compliant compiler complain rather bitterly. |
Re: _set_new_handler() problem header?
The book was really outdated, but the way the author presented the features of c++ is very simple and easy to understand, he presented the features of c++ in real life situations unlike other books which contains bag of tricks,but does not show on how it can be applied in real life programming, I read another book titled "accelerated c++" but the way he presented the information makes me hard to grasp. I am not really good in english so i am having a really hard time understanding other books, but the book i am reading really suits me, so what i do is practicing and coding the information on the book and supplementing it with other reference books.... Anyway, thanks a lot grumpy, you are too cool knowing lots of stuff in programming, I envy you a lot... more power! thank you
|
Re: _set_new_handler() problem header?
I sympathise on the problem of finding easy to read books on C++ for beginners; the most knowledgeable authors tend to write in a style that assumes the reader is interested in concepts rather than practice, and also has a solid grasp of the fundamentals of the language. Unfortunately, information that is simple and easy to understand is worthless if it is wrong and, if it is believed by beginners, does more harm than good.
|
Re: _set_new_handler() problem header?
Quote:
|
Re: _set_new_handler() problem header?
If the author of your book is Herbert Schildt, I'd recommend using it only as a paperweight, doorstop, fuel for the fireplace, or page-by-page as cat box liner. Really, he's got that bad of a reputation- so bad, in fact, that the term 'bullschildt' was coined to describe his writings.
|
Re: _set_new_handler() problem header?
Quote:
|
Re: _set_new_handler() problem header?
Well, now you know what to do with that Schildt book. ;)
|
Re: _set_new_handler() problem header?
Quote:
|
| All times are GMT -5. The time now is 4:14 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC