Overloaded global delete is used instead of orignal global delete[]

A

Alex Vinokur

Hi,

It seems that overloaded global delete is used instead of orignal
global delete[] in program below.

Any suggestions?

Thanks


// ===========================================
// File foo1.cpp
#include <memory>
#include <iostream>

#define SHOW_FUNC std::cout << "Line-" << __LINE__ << ": " <<
__PRETTY_FUNCTION__ << std::endl

// ---------------------------------
// Global delete
// ---------------------------------


void operator delete(void *i_p)
{
SHOW_FUNC; // Line-13
// Do something
free(i_p);
}

// ---------------------------------
struct Foo
{
};



// ====================
int main()
{
Foo* p = ::new Foo[2];
::delete [] p;

return 0;
}

// ===========================================


Linux
gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)
g++ foo1.cpp
// No errors


Output
Line-13: void operator delete(void*) // So, overloaded global
delete is used instead of orignal global delete[] ?
 
K

Kalle Olavi Niemitalo

Alex Vinokur said:
It seems that overloaded global delete is used instead of orignal
global delete[] in program below.

::delete[] p calls the default ::eek:perator delete[](void*), which
then calls your ::eek:perator delete(void*) as required by C++11
[new.delete.array].
 
A

Alex Vinokur

Alex Vinokur said:
It seems that overloaded global delete is used instead of orignal
global delete[] in program below.

::delete[] p calls the default ::eek:perator delete[](void*), which
then calls your ::eek:perator delete(void*) as required by C++11
[new.delete.array].

Thanks. But it is not C++11, it is "old" C++.
 
Z

Zoltan Juhasz

Wording is a bit different (98/03), otherwise requires the same behavior asdescribed below.

Alex Vinokur said:
It seems that overloaded global delete is used instead of orignal
global delete[] in program below.

::delete[] p calls the default ::eek:perator delete[](void*), which
then calls your ::eek:perator delete(void*) as required by C++11
[new.delete.array].

Thanks. But it is not C++11, it is "old" C++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top