Suppose the following template definition (code does not make sense):
template<class X, class Y>
bool FooBar(const Y& val) { return sizeof(X) + 4; }
I found that the following call code is legal:
float temp = 0.f;
FooBar<int>(temp);
As you can see, the parameter of the second type Ycan be omitted. The compiler infers the type Yby looking at the type of the argument temp.
Does this rule or C ++ template spec allow this? I was very surprised to see this.
source
share