C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

two operator delete

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Bo Rong
Guest





PostPosted: Thu Apr 29, 2004 9:11 pm    Post subject: two operator delete Reply with 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?

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





PostPosted: Fri Apr 30, 2004 11:28 am    Post subject: Re: two operator delete Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.