473,390 Members | 1,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 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 2294
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Edward Diener | last post by:
Is it possible for a derived class to override a property and/or event of its base class ?
3
by: Cheng Mo | last post by:
When overriding operator new & delte of one class, the method is implicitly declared as static. However, overriding operator new & delete of template cannot be static.The compiler says cannot...
6
by: shoosh | last post by:
hi for my application under VC6 I need to implement my own memory manager which overrides the global new and delete operators and which Do Not use the normal free() and malloc(). it seemed to...
3
by: Gonçalo Rodrigues | last post by:
Hi all, I have a base class, call it Object, that implements operators new and delete. Now suppose there is also a class, call it Derived, deriving from Object. It has the feature that *all*...
2
by: byoukstetter | last post by:
So, I have an interface with several overriding methods: using System; using System.Collections.Specialized; namespace some.name.space { public interface IVrsPersistenceProvider { string...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
9
by: groleo | last post by:
Hi list. Simple question: is it possible to override the global new/delete operators, without using malloc/free? I mean something in the ideea of the code below, which doesnt work cause of...
4
by: tomlong | last post by:
Hi, I have a tabular form that each TR has an onclick event to edit the row. I also have a div in one of the cells on each row that is a delete button. My problem is that both onclicks are being...
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.