delete operator override
-
I'm trying to override the global delete operator.
void operator delete(void* pAddr)
{
...
}In this method I do some work and then I would like to call the default delete. However
::delete(pAddr)
always call my delete operator. In my code I have to use delete p; which should call my operator but within my operator I would like to call the default system defined delete operator. Any idea how to call (obtain) the default delete operator? Thanks, Abyss
-
I'm trying to override the global delete operator.
void operator delete(void* pAddr)
{
...
}In this method I do some work and then I would like to call the default delete. However
::delete(pAddr)
always call my delete operator. In my code I have to use delete p; which should call my operator but within my operator I would like to call the default system defined delete operator. Any idea how to call (obtain) the default delete operator? Thanks, Abyss
Abyss wrote:
In this method...I would like to call the default delete.
How about calling
free(pAddr)
instead?"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Abyss wrote:
In this method...I would like to call the default delete.
How about calling
free(pAddr)
instead?"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Not sure if it is OK. My understanding is that a pointer allocated by new operator should be freed by delete and call free on the pointer can cause problems...
Abyss wrote:
My understanding is that a pointer allocated by new operator should be freed by delete and call free on the pointer can cause problems...
True, but since you are also overriding the global
new
operator (hint: you are doing this, aren't you?), that is not an issue."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Not sure if it is OK. My understanding is that a pointer allocated by new operator should be freed by delete and call free on the pointer can cause problems...
Probably you can't. Furthermore, if you override
delete
then you've also to overridenew
, see, for instance [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Abyss wrote:
My understanding is that a pointer allocated by new operator should be freed by delete and call free on the pointer can cause problems...
True, but since you are also overriding the global
new
operator (hint: you are doing this, aren't you?), that is not an issue."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
DavidCrow wrote:
you are doing this, aren't you?
:laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Abyss wrote:
My understanding is that a pointer allocated by new operator should be freed by delete and call free on the pointer can cause problems...
True, but since you are also overriding the global
new
operator (hint: you are doing this, aren't you?), that is not an issue."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
You're too fast... :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I'm trying to override the global delete operator.
void operator delete(void* pAddr)
{
...
}In this method I do some work and then I would like to call the default delete. However
::delete(pAddr)
always call my delete operator. In my code I have to use delete p; which should call my operator but within my operator I would like to call the default system defined delete operator. Any idea how to call (obtain) the default delete operator? Thanks, Abyss
Hmm. It strikes me that you have reached a language boundary. Under the cpp model, you can only override functions as follows:; Member Functions in a Derrived Class with the same Param list, Member Functions in your original + Derrived Class class with different Param Lists. Global Functions with different parameter lists. 'delete' is not a global function, but a keyword like 'if' and 'for' you can override it with your own implementation, but, if you do so, you replace it. That is only possible because it is a keyword. If it were a global function, you would not be able to re-define it at all. (you'd get all types of linker errors) My advice is: Re-Design the Code. regards, :)
Bram van Kampen
-
Abyss wrote:
My understanding is that a pointer allocated by new operator should be freed by delete and call free on the pointer can cause problems...
True, but since you are also overriding the global
new
operator (hint: you are doing this, aren't you?), that is not an issue."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
delete is a keyword, not a global function!!! :)
Bram van Kampen
-
You're too fast... :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]delete is a Keyword, NOT a global function :)
Bram van Kampen