 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bo Rong Guest
|
Posted: Thu Apr 29, 2004 9:11 pm Post subject: two operator delete |
|
|
hello, everyone. i have a question about operator overload.
in some class, i have overload following 3 operators,
class A
{
1)
static void * operator new( size_t size )
{
....
}
2)
static void operator delete( void *p, size_t size )
{
....
}
3)
static void operator delete( void *p )
{
....
}
};
then, i wonder compiler will call 2) or 3 ) when i delete a pointer to A
object?
what differences between them?
thanks for your response.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Stephen C. Dewhurst Guest
|
Posted: Fri Apr 30, 2004 11:28 am Post subject: Re: two operator delete |
|
|
On 29 Apr 2004 17:11:02 -0400, "Bo Rong" <rong_bo (AT) trendmicro (DOT) com.cn>
wrote:
| Quote: | hello, everyone. i have a question about operator overload.
in some class, i have overload following 3 operators,
class A
{
1)
static void * operator new( size_t size )
{
...
}
2)
static void operator delete( void *p, size_t size )
{
...
}
3)
static void operator delete( void *p )
{
...
}
};
then, i wonder compiler will call 2) or 3 ) when i delete a pointer to A
object?
what differences between them?
|
Both versions of operator delete declared above are "usual" versions
(according to the standard). If one or the other is present, it will
be called in a delete expression. If both are present, then the
single argument version will be preferred, and the 2-argument version
will be called only in special circumstances (in the presence of a
bad_alloc exception from an overloaded operator new or in the case of
an explicit call to operator delete).
Generally, it's best to decide on one version of the "usual" versions
of operator delete or the other. Typically, the 2-argument version is
preferable.
Steve
www.semantics.org
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|