I've been experimenting with the use of (nothrow) with operator new but I
can't seem to get it to compile. I've done a bunch of reading and everything
I've read seems to indicate that I'm doing it properly but still no luck. If
anyone can shed some light on the problem, it would be greatly appreciated.
I am using VC++ .Net (7.1.3088) if it helps.
The Code
=======
#include <new>
using std::nothrow;
...
int* piMyInt = new(std::nothrow) int;
The Compile Error
=============
error C2061: syntax error : identifier 'nothrow'
-Ganesh
"Kris" wrote:
> Hi All,
>
> I've been experimenting with the use of (nothrow) with operator new but I
> can't seem to get it to compile. I've done a bunch of reading and everything
> I've read seems to indicate that I'm doing it properly but still no luck. If
> anyone can shed some light on the problem, it would be greatly appreciated.
> I am using VC++ .Net (7.1.3088) if it helps.
>
>
> The Code
> =======
> #include <new>
> using std::nothrow;
> ....
>Hi All,
>
>I've been experimenting with the use of (nothrow) with operator new but I
>can't seem to get it to compile. I've done a bunch of reading and everything
>I've read seems to indicate that I'm doing it properly but still no luck. If
>anyone can shed some light on the problem, it would be greatly appreciated.
>I am using VC++ .Net (7.1.3088) if it helps.
>
>
>The Code
>=======
>#include <new>
>using std::nothrow;
Why have you got the using declaration?
>...
>int* piMyInt = new(std::nothrow) int;
>
>
>The Compile Error
>=============
>error C2061: syntax error : identifier 'nothrow'
Which line does the error point to?
This exact code:
#include <new>
using std::nothrow;
int* piMyInt = new(std::nothrow) int;
compiles without error for me. Have you got a '#define new' type
construct anywhere? MFC has that, as do some other libraries.
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
After doing some more digging, I discovered that DEBUG_NEW is a MS macro
that allows VC++ to keep track of the filename and line number for each of
the items that it allocates. The following article on MSDN has further
details:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_debug_new.asp
My solution was to simply comment out that block of code in the file where I
was getting the compile error. Do you have any opinions on whether or not
this was the right approach to take? I would like the compiler to still be
able to keep track of the line number/file but not at the expense of being
able to specify nothrow.
"tom_usenet" <tom_u...@hotmail.com> wrote in message
news:bi76d0lloooho37qt...@4ax.com...