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 

a question about placement operate delete

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





PostPosted: Thu Oct 30, 2003 4:11 pm    Post subject: a question about placement operate delete Reply with quote



the question with Borland C++ BuilderX 1.0's Compile:
class A
{
public:
void * operator new (size_t size) { ... }
void operator delete (void *p) { ... }

void * operator new (size_t size, void *p) { ... }
//placement new
void operator delete(void *p1, void *p2) { ... }
//placement delete
};

that whas error with two "operator delete functions"

with "void operator delete(void *p1, void *p2) { ... } "
1.cpp": E2238 Multiple declaration for 'A' at line 21

with "void operator delete (void *p) { ... }"
1.cpp": E2344 Earlier declaration of 'A' at line 10

when i removed *ANY* one of the "operator delete" function, that was
ok.

is the void operator delete (void *p1, void *p2) do nothing with
placement operator new ?, because the C++BuilderX 's help document
wrote:

The second function (means: void operator delete(void *, void *); ) is
called by a placement delete expression corresponding to a new
expression of the form new(std::size_t). It does nothing.


thanks all anyway.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ivan Vecerina
Guest





PostPosted: Sat Nov 01, 2003 10:06 am    Post subject: Re: a question about placement operate delete Reply with quote



"DarkSpy" <coneos (AT) 21cn (DOT) com> wrote

Quote:
the question with Borland C++ BuilderX 1.0's Compile:
class A
{
public:
void * operator new (size_t size) { ... }
void operator delete (void *p) { ... }

void * operator new (size_t size, void *p) { ... }
//placement new
void operator delete(void *p1, void *p2) { ... }
//placement delete
};

that whas error with two "operator delete functions"

I believe this code is ok, and this could be
a limitation of the compiler.

......
Quote:
when i removed *ANY* one of the "operator delete" function, that was
ok.

is the void operator delete (void *p1, void *p2) do nothing with
placement operator new ?, because the C++BuilderX 's help document
wrote:

The second function (means: void operator delete(void *, void *); ) is
called by a placement delete expression corresponding to a new
expression of the form new(std::size_t). It does nothing.

The placement-delete function is only called when a call to
the corresponding placement-new function throws an exception.
For the classic placement-new (to create an object at a
specified address), the matching delete should indeed do
nothing.
If the placement-new function above never throws an exception,
simply omitting the placement-delete function could be
a safe workaround.

Ivan
--
http://ivan.vecerina.com
Brainbench MVP for C++ <> http://www.brainbench.com



[ 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.