I was trying to learn how to overload the new operator, but the code doesn´t work as it should. What is wrong?
It doesn´t print the message.Code:#include <iostream> using namespace std; class Example { public: Example(){ cout << "Constructor called"; } void* operator new(size_t size){ return(new Example()); } }; int main() { Example *ob1; ob1 = new Example(); return 0; }
Thanks any help!