Please note that the following two functions are of the same type and signature:
void foo1(int t) {} // foo1 has type 'void(*)(int)', and signature '(*)(int)' void foo2(const int t) {} // Also type 'void(*)(int)', signature '(*)(int)'
( const not part of a function type or function signature). Similarly, a modifier ( const or volatile ) on the type of the return value does not affect the type of the function or the signature of the function.
However, in the function definition itself (not shown), the named variable t supports the const qualification in foo2 .
There are many StackOverflow questions discussing why the return type of a function is not considered as part of the function signature (used to allow overloading).
However, I cannot find a StackOverflow question that asks why argument modifiers ( const or volatile ) are not part of a function type or signature. Also, I looked right in the C ++ 11 standards document and it's hard to figure out.
What is the rationale for the fact that argument modifiers (i.e., const and volatile ) are not part of a function or signature type?
ADD . For clarity, from R.MartinhoFernandes below, I should clarify that in C ++ (I think) the modifiers of the const and volatile arguments are ignored only as part of the type of the / signature function if they are top-level modifiers - see this answer below.
source share