Re: How to externally impose operators new/delete
In article <1183978050.077637.160950@q75g2000hsh.googlegroups.com>,
CodeCracker <sanjaym365@gmail.com> wrote:
{ Quoted clc++m banner removed. Please don't quote it. Tip: decent
newsreader client programs remove it automatically. -mod }
On Jul 6, 4:47 pm, Zeljko Vrba <zvrba.nos...@ifi.uio.no> wrote:
I guess that the "usual" way to impose new/delete upon a class X is to
derive from X, as in:
class X1 : public X {
void *operator new(size_t);
void operator delete(void*);
};
'
or derive X from a templated struct like:
template <class Derived> struct allocation
{
void * operator new (size_t) { /* default op new desired */}
void operator delete(void *) { /* default op delete desired */}
};
for each class needing different allocation specialize the template.
templae <> struct allocation<X>
{
void *operator new(size_t);
void operator delete();
};
class X:public allocation<X>
{
// ....
};
template <>
void * allocation<X>::operator new ()
{
// impliment it
}
template <>
void allocation<X>::operator delete(void *)
{
// implement it
}
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]