sizeof() is look like function but i don’t know sir why are you calling operator
Size of Operator 6110
@khemchandrs https://stackoverflow.com/questions/1393582/why-is-sizeof-considered-an-operator
Refer this
i did not understand why is sizeof() function
@khemchandrs Some noticeable things to make sure sizeof() is an operator an not a function :
- It works on compile time unlike functions which are run time entities.
- It operates on types: sizeof(int), sizeof(int*), sizeof(std::string). This is not a syntax of a function call.
- It does not require parentheses when operating on expressions: sizeof a; sizeof &n; sizeof std::cout;. Once again, this is not a syntax of a function call.
if i want make user defined operator like sizeof
then what should do like sizeof operator
Using templates you can implement a sizeof function somewhat like this:
template < class Type >
int mysizeof( const Type &)
{
Type arr[2];
return (long int)&arr[1]-(long int)&arr[0];
}
//pass in variable of required datatype