namespace X
{
void* operator new (size_t);
}
gives error message as:
error: ‘void* X::operator new(size_t)’ may not be declared within a namespace
Is it a gcc compiler bug ? In older gcc version it seems to be working.
Any idea, why it's not allowed ?
Use case:
I wanted to allow only custom operator new/delete
for the classes and wanted to disallow global new/operator
. Instead of linker error, it was easy to catch compiler error; so I coded:
namespace X {
void* operator new (size_t);
}
using namespace X;
This worked for older version of gcc but not for the new one.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…