Overriding new and delete again...

J

Jesper Madsen

Can I confine overrides of new and delete to certain namesspaces, f.ex. by
just introducing the modfied operator new in namespace GUI?? Or should I
ask, if I declare operator new in a namespace, is it still global operator
new I define??

This is just for doing some memory tracking, so it would be nice if I could
keep namespace std:: out of the game.. and avoid STL.

I do not have any using std namespace; or such in my code, so this will not
bother me..

Jesper
 
B

Boris Kolpackov

Jesper Madsen said:
Can I confine overrides of new and delete to certain namesspaces, f.ex. by
just introducing the modfied operator new in namespace GUI?? Or should I
ask, if I declare operator new in a namespace, is it still global operator
new I define??

3.7.3.1/1:

An allocation function shall be a class member function or a global function;
a program is ill-formed if an allocation function is declared in a namespace
scope other than global scope or declared static in global scope.

3.7.3.2/1:

Deallocation functions shall be class member functions or global functions;
a program is ill-formed if deallocation functions are declared in a namespace
scope other than global scope or declared static in global scope.


The closest you can get is by using a common base for your GUI objects. E.g.:

namespace GUI
{
struct Object
{
static void*
operator new (size_t) throw (std::bad_alloc);

static void
operator delete (void*);

// ...

};

class Window : public virtual Object
{
// ...
};
}

hth,
-boris
 

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,773
Messages
2,569,594
Members
45,126
Latest member
FastBurnketoIngredients
Top