define for overloaded new

A

Alex Vinokur

Hi,

I need to overload new operator.
Hoever, there is some problem with new (std::nothrow).


Is there any way to resolve the problem without '#undef new' below?



--------------------------------------
#define NEW new(size, __FILE__, __LINE__)
#define new NEW



int main()
{
char* p1 = new char; // Actiually new(size, __FILE__, __LINE__)


#ifdef new
#undef new
char* p2 = new (std::nothrow) char;
#define NEW
#endif
}
--------------------------------------
 
B

Bo Persson

Alex Vinokur skrev 2012-06-23 07:33:
Hi,

I need to overload new operator.
Hoever, there is some problem with new (std::nothrow).


Is there any way to resolve the problem without '#undef new' below?



--------------------------------------
#define NEW new(size, __FILE__, __LINE__)
#define new NEW



int main()
{
char* p1 = new char; // Actiually new(size, __FILE__, __LINE__)


#ifdef new
#undef new
char* p2 = new (std::nothrow) char;
#define NEW
#endif
}

No, you cannot override any operator new in places where this macro is
visible. You have to choose one or the other.


Bo Persson
 
A

Alex Vinokur

Hi,

I need to overload new operator.
Hoever, there is some problem with new (std::nothrow).

Is there any way to resolve the problem without '#undef new' below?

--------------------------------------
#define NEW new(size, __FILE__, __LINE__)
#define new NEW

int main()
{
   char* p1 = new char;    // Actiually new(size, __FILE__, __LINE__)

#ifdef new
#undef new
   char* p2 = new (std::nothrow) char;
#define NEW
#endif}

--------------------------------------

......
char* p2 = new (std::nothrow) char;
#define new NEW // here was a typo in original post
......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top