0
Void prints out double not int
Why does a void function that prints out two variables sum print a double when it receives a double and an int? #include <iostream> using namespace std; template <class T, class U> void smaller(T a, U b) { cout << a+b; } int main () { int x=72; double y=15.34; smaller(x, y); }
3 Antworten
+ 5
http://icecube.wisc.edu/~dglo/c_class/promo_conv.html
describes when types are "promoted"
e.g., because one data type is assumed to be more efficient
and "converted"
e.g., to "raise an expression to the largest datatype"
These are guards against undefined behavior and efficiency/precision loss.
+ 4
Can we see the code?
Most likely one of the variables was a double. So the int was upcasted.
+ 1
Thanks for the help😊