#include <new> and the three operator new functions

Hi,

According to the reference entry for operator new
( http://www.cplusplus.com/reference/std/new/operator%20new/ ) :


Global dynamic storage operator functions are special in the standard library:

* All three versions of operator new are declared in the global namespace, not in the std namespace.
* The first and second versions are implicitly declared in every translation unit of a C++ program: The header <new> does not need to be included for them to be present.



This seems to me to imply that the third version of operator new is not implicityly declared in every translation unit of a C++ program and the header <new> does need to be included for it to be present.

However using both g++ and MS VC++ Express compilers it seems I can compile code using the third version of new without #include <new> in my source code.

Can anyone explain this behaviour? Thanks.
Last edited on
1
2
3
int main() {
    int* p = new (nothrow) int( 6 );
}



/> g++ f.cpp
f.cpp: In function ‘int main()’:
f.cpp:2: error: ‘nothrow’ was not declared in this scope
/> g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


You might be including other headers that are including <new> for you.
Thanks.
Topic archived. No new replies allowed.