Overloading 'new' as in gcc

Started by
1 comment, last by Nurtsi 22 years, 9 months ago
Is it possible (and how) to overload operator new as static in gcc. Works fine with VC6 like this: static inline void* operator new(size_t) However, gcc (atleast v2.96) gives error operator new was declared extern (in file 'new' that comes with the compiler) then static. Is there a way around this? If I can't declare new and delete as static they mess up my memory allocation routines. - Nurtsi Edited by - Nurtsi on July 21, 2001 5:03:37 AM
Advertisement
I am guessing that overloading new and delete on a static level is probably illegal. Because this could result in a mismatch such as using a normal delete on a specialised new or vice versa.

Is it impossible for you to overload it on a per-class basis?
I need to overload the global new and delete to allocate memory for buffers and such. If I want to allocate memory, for example, for a bitmap, I can''t use any class specific operators.

Declaring overloaded operators as static I can use my own operators for my code and the standard new and delete for other code, like STL. I can''t seem to avoid breaking STL with my own operators. Hence the need for static.

- Nurtsi

This topic is closed to new replies.

Advertisement