#define style templates and float
-
Hi guys, I tried to compile and run a #define type templates example code in Visual C++:
#include #define define_max(type) \ type max(type d1, type d2) { \ if (d1 > d2) \ return (d1); \ return (d2); \ } define_max(int); define_max(float); define_max(char); int main(void) { int i = max(100, 800); char ch = max('A', 'Q'); float f = max(3.5, 8.7); return 0; }
and I am getting compile error
ambiguous call to overloaded function
on the linefloat f = max(3.5, 8.7);
If I replace float with double, it will compile and run ok. Does anyone know why that is? Is there some kind of limitation on uses of float in Visual C++? Thanks alot
-
Hi guys, I tried to compile and run a #define type templates example code in Visual C++:
#include #define define_max(type) \ type max(type d1, type d2) { \ if (d1 > d2) \ return (d1); \ return (d2); \ } define_max(int); define_max(float); define_max(char); int main(void) { int i = max(100, 800); char ch = max('A', 'Q'); float f = max(3.5, 8.7); return 0; }
and I am getting compile error
ambiguous call to overloaded function
on the linefloat f = max(3.5, 8.7);
If I replace float with double, it will compile and run ok. Does anyone know why that is? Is there some kind of limitation on uses of float in Visual C++? Thanks alot
This is just a guess, but try replacing the four occurrences of
max()
with something likemax1()
.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Hi guys, I tried to compile and run a #define type templates example code in Visual C++:
#include #define define_max(type) \ type max(type d1, type d2) { \ if (d1 > d2) \ return (d1); \ return (d2); \ } define_max(int); define_max(float); define_max(char); int main(void) { int i = max(100, 800); char ch = max('A', 'Q'); float f = max(3.5, 8.7); return 0; }
and I am getting compile error
ambiguous call to overloaded function
on the linefloat f = max(3.5, 8.7);
If I replace float with double, it will compile and run ok. Does anyone know why that is? Is there some kind of limitation on uses of float in Visual C++? Thanks alot
3.5 and 8.7 are consider constant doubles. When I compile the code below, VC gives me a warning for "a" but not for "b"
float a = 2.4; warning C4305: 'initializing' : truncation from 'const double' to 'float' float b = 2.4f;
-
3.5 and 8.7 are consider constant doubles. When I compile the code below, VC gives me a warning for "a" but not for "b"
float a = 2.4; warning C4305: 'initializing' : truncation from 'const double' to 'float' float b = 2.4f;