Hello,
I went through a C++ program to handler memory management via "new".
It used a set_new_handler() function which prints a error message when
any memory exhaustion occurs.
I tried using that in my C++ program in Linux but my compiler (gcc)
reported a error saying:
test11.cpp: In function 'int main()':
test11.cpp:8: error: variable or field 'set_new_handler' declared void
test11.cpp:8: error: invalid lvalue in unary '&'
test11.cpp:14: error: 'set_new_handler' cannot be used as a function
I am pasting my program too:
#include <iostream>
#include <stdlib.h>
#include <new>
using namespace std;
main()
{
void memwarning();
void set_new_handler(memwarning);
char *p=new char[100];
cout << "First allocation: p = " << hex << long(p) << endl;
p=new char[64000u];
set_new_handler(0);
}
void memwarning()
{
cout << "Free store exhausted" << endl;
exit(1);
}
Please help.
Regards