-1

I have following code:

  template<int FORMAT>
  int double_to_bulk(double value,
                       char* buf,
                       double max_num,
                       int* state = NULL)
  {
     if (isnan(value))
     {
        //Something to do
        return 1;
     }
     //Something more to do
  }

And strange compilation error:

myfile.h: In function ‘int double_to_bulk(double, char*, double, int*)’:

myfile.h:351: error: there are no arguments to ‘isnan’ that depend on a template parameter, so a declaration of ‘isnan’ must be available

myfile.h:351: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)

But I really don't want to use -fpermissive

I use gcc 4.1.2, quite old, but nothing to do with it. Why is it problem to use isnan in template function?

Arkady
  • 2,084
  • 3
  • 27
  • 48
  • in C99 it exists as a macros. And yes, it was simply not defined. I just was confused by such strange compiler message. – Arkady Mar 27 '16 at 13:31

2 Answers2

1

It looks like you don't have an available definition for isnan. Have you included in your source the appropriate header file where isnan is defined? Nothing at all here seems to depend on your template parameter.

Logicrat
  • 4,438
  • 16
  • 22
  • Yes, moving it out to another function shows that it was not defined. I just was confused by such message of compiler. – Arkady Mar 27 '16 at 13:30
0

Adding the line #include<cmath> should fix the problem.

If any arguments did dependent on a template parameter (e.g. if one of the arguments had a template-parameter type), the compiler will only check for existence of isnan when you instantiate the template, which would probably cause an error anyway, just later, or potentially not at all if you never use the template.

DO NOT use -fpermisive, it would probably just delay the error to link time

Isaac
  • 816
  • 5
  • 12