Hi all,
I'm new to working with C++ (I'm more a C programmer) and I have a question:
I have a container class for a templated type T, which could be any scalar type, although the most commonly used ones are unsigned char and float.
I have a function that prints some of the elements to screen:
template <class T>
void dumpImageAscii(
const Image2D<T> *image,
const char *file_name)
{
...
bool is_int = numeric_limits<T>::is_integer;
....
for (v = image->bounds._l2; v <= image->bounds._h2; v++)
{
for (u = image->bounds._l1; u <= image->bounds._h1; u++)
{
if (is_int)
fprintf(pFile, "%10d", image->m[v][u]);
else
fprintf(pFile, "%16g", image->m[v][u]);
}
fprintf(pFile, "\n");
}
....
}
Although the is_int flag takes care of formatting when printing, the compiler still throws a warning every time I call this function, stuff like:
warning: format ‘%10d’ expects type ‘int’, but argument 3 has type ‘double’
Which is expected because it's not smart enough to figure out which tree to go in at compile time.
I do not like seeing warnings in my code, especially unnecessary warnings like these...
Is there a way around this?
Also I want to avoid cout/fout whenever possible...most of the project is straight C, it's just that we need templates for this part.
Thanks.