1
$\begingroup$

As I understand, C++ in general features 'one-way' type checking. That is checking the sub-expressions and get their types, and see if the types so far satisfy the constraints imposed by the current expression node. It's an algorithm progressing from bottom to top.

However, C++ also features overloading and template. When you pass such a function directly as the argument to another function, during type checking we cannot immediately get the type of the sub-expression since it is overloaded or using template. So how does it work?

It's possible that C++ does more than 'one-way' type checking. If that's the case, please explain to me how the feature is implemented.

$\endgroup$

1 Answer 1

1
$\begingroup$

Type checking occurs when the template is instantiated, so the compiler knows the types by then.

Overload resolution happens at call site. The sub-expressions are the arguments, when their types is known the resolution can occur, hence giving the type of the call expression (that is, the return type).

Neither templates nor overloaded functions are first-class citizen constructs than can be passed around, so I am not sure what you mean by "such a function".

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.