 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
DarkSpy Guest
|
Posted: Thu Oct 30, 2003 4:11 pm Post subject: a question about placement operate delete |
|
|
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
|
Posted: Sat Nov 01, 2003 10:06 am Post subject: Re: a question about placement operate delete |
|
|
"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 |
|
 |
|
|
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
|
|