Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Questions about Templates

$
0
0
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?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>