|
From: Lloyd <ll...@cd...> - 2007-05-16 14:43:45
|
Hi,
I want to overload the new operator. My requirement is to print a
message and use the global operator new from the overloaded new
"function". I am using the global new in my program I just want it to
use my overloaded new by just including a namespace... This is the way I
am trying to implement it... but compiler gives me the errors... How can
I do this?
The code:-
#include<iostream>
using namespace std;
namespace x
{
void* operator new(size_t);
}
void* x::operator new(size_t x)
{
cout<<"hai"<<endl;
//how to use global new instead of malloc?
return malloc(x);
}
using namespace x;
int main()
{
int *a=new int(1);
return 0;
}
This is the error:-
operator.cpp:20: error: call of overloaded `operator new(unsigned int)'
is ambiguous
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c+
+/3.4.3/new:82: note: candidates are: void* operator new(size_t)
operator.cpp:10: note: void* x::operator new(size_t)
Thanks and Regards,
Lloyd
Awaiting for your help :)
______________________________________
Scanned and protected by Email scanner
|