To my understanding, new operator calls operator new (which works like malloc) and then calls the constructor for the object (defined in it's class). So as going by the name operator new is also an operator.
If yes, then how can the number of operands be changed when operator new is redefined(overloading the operator). Changing of the number of operands for an operator is not allowed in c++ (as far as my knowledge goes). A unary operator can't be changed into binary (like + can't be overloaded as a ternary operator)
basically, how does this work ?(operator new is supposed to be a unary operator as far as my understanding goes, correct me if I am wrong)
void *operator new(size_t size, char c)
{
void *ptr;
ptr = malloc(size);
if (ptr!=NULL)
*ptr = c;
return ptr;
}
main()
{
char *ch = new('#') char;
}
P.S If operator new is actually a function then why is it overloaded as an operator ?