I was doing an experiment, code below:
template<typename T>
struct S
{
explicit S(T v) :val{ v } {};
T val;
};
int main()
{
S<int> MyS('g');
cout << MyS.val << endl;//Output is 103
return 0;
}
Even though I am providing T with a type which is int, and I have an explicit constructor, why I have an implicit conversion from char to int? Shouldn't it see that T is int since I'm telling it so and thus give me error for constructing an S out of char?
↧