I have a point in my mind that I cannot understand about the new operator overload. Suppose I have a class MyClass, but the files MyClass.h MyClass.cpp and main.cpp are similar;
//MyClass.h class MyClass { public: //Some member functions void* operator new (size_t size); void operator delete (void* ptr); //... }; //MyClass.cpp void* MyClass::operator new(size_t size) { return malloc(size); } void MyClass::operator delete(void* ptr) { free(ptr); } //main.cpp //Include files //... int main() { MyClass* cPtr = new MyClass(); delete cPtr }
respectively. This program works great. However, I cannot understand why the new operator can be called without any parameter, whereas in its definition it has a function parameter, such as "size_t size". Is there an item that I am missing here? Thanks.
mecid source share