![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 40
Rep Power: 0
![]() |
_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
c++ Syntax (Toggle Plain Text)
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
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,192
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#3 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 40
Rep Power: 0
![]() |
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
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,192
Rep Power: 5
![]() |
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.
|
|
|
|
|
|
#5 | |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 40
Rep Power: 0
![]() |
Re: _set_new_handler() problem header?
Quote:
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
|
|
|
#6 |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 889
Rep Power: 4
![]() |
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.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
#7 | |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 40
Rep Power: 0
![]() |
Re: _set_new_handler() problem header?
Quote:
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
|
|
|
#8 |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 889
Rep Power: 4
![]() |
Re: _set_new_handler() problem header?
Well, now you know what to do with that Schildt book.
![]()
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
#9 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 40
Rep Power: 0
![]() |
Re: _set_new_handler() problem header?
The Schildt book is just for reference hehehehehe.... do you have any good book to recommend?
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem solving | ReggaetonKing | Software Design and Algorithms | 7 | Jan 4th, 2008 1:49 PM |
| problem processing file into a char array | csrocker101 | C++ | 1 | May 8th, 2007 11:50 PM |
| send() problem w/ http server | kch_86 | C | 2 | Nov 25th, 2005 12:53 AM |
| question about header files and prototyping functions | linuxpimp20 | C | 13 | Sep 7th, 2005 8:28 AM |
| TCP Header for Echo Communication | AusTex | C++ | 0 | Feb 27th, 2005 3:57 PM |