PDA

View Full Version : c++ #include<new>



guest_user
November 4th, 2008, 02:47 AM
what is this library for?
I don't need to add in #include<new>
to dynamically allocate memory right?
as in
int *pointer = new int;

From here:
http://www.cplusplus.com/doc/tutorial/dynamic.html

it says that in new (nothrow) int;, the nothrow object is declared in the new library but when I tried compiling my program without the header file, no errors were given to me by the compiler and everything worked as per normal, so whats the purpose of the new library?

LaRoza
November 4th, 2008, 03:03 AM
The standard libs are often automatically linked.

http://en.wikipedia.org/wiki/C%2B%2B_standard_library

guest_user
November 4th, 2008, 07:09 AM
but if that is so, why is it that iomanip is not automatically linked when I want to use setprecision() while new library is automatically linked when I want to use new since both belong to the c++ standard library?

LaRoza
November 4th, 2008, 07:27 AM
but if that is so, why is it that iomanip is not automatically linked when I want to use setprecision() while new library is automatically linked when I want to use new since both belong to the c++ standard library?

#include has nothing to do with linking, in case my post was confusing. If you don't link iomanip, then it is automatically linked.

It would depend on the contents of those headers. I have little interest in C++, and haven't touched it recently (my ten foot pole is out for repairs). If the headers' contents were needed, it would matter.