471,585 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,585 software developers and data experts.

Overriding new and delete again...

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
Jul 19 '05 #1
1 2239
"Jesper Madsen" <ba***@mail.stofanet.dk> writes:
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

--
Boris Kolpackov http://kolpackov.net
3072R/AE084F1D - F608 942F 312E D82E 5B84 0407 C880 290B AE08 4F1D
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Edward Diener | last post: by
3 posts views Thread by Cheng Mo | last post: by
6 posts views Thread by shoosh | last post: by
3 posts views Thread by Gonçalo Rodrigues | last post: by
2 posts views Thread by byoukstetter | last post: by
17 posts views Thread by Bob Weiner | last post: by
9 posts views Thread by groleo | last post: by
4 posts views Thread by tomlong | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.