I know that there should be a delete operator with which I am not interested somewhere. I'm just curious, wow, it worked. Where is the argument "size" coming from?
#include<iostream> #include<string> class Base { public: Base() { } void *operator new( unsigned int size, std::string str ) { std::cout << "Logging an allocation of "; std::cout << size; std::cout << " bytes for new object '"; std::cout << str; std::cout << "'"; std::cout << std::endl; return malloc( size ); } private: int var1; double var2; }; int main(int argc, char** argv){ Base* b = new ("Base instance 1") Base; }
Here is the result:
Record of allocation of 16 bytes for a new object "Basic instance 1"
source share