Invalid conversion from 'int' to 'double*'

后端 未结 4 1522
暖寄归人
暖寄归人 2021-01-25 07:52

I have this line of code:

int g = modf(ans*power, 1)*10;

And it is giving me the error:

Invalid conversion from \'int\'

相关标签:
4条回答
  • 2021-01-25 08:01

    modf expects a pointer to a double as its second argument. See here.

    0 讨论(0)
  • 2021-01-25 08:05

    modf(ans*power, 1) is bad

    double smthng = 1.0; modf(ans*power, &smthng) is good.

    http://linux.die.net/man/3/modf

    0 讨论(0)
  • 2021-01-25 08:10
    modf(double x, double * intpart);
                         ^^^
    

    See modf

    0 讨论(0)
  • 2021-01-25 08:12

    I don't see where I am using a pointer : you're not, and that is the problem. Look at the signature of modf:

    double modf( double, double* );
    

    It requires a double* as second argument; you're passing it an int.

    0 讨论(0)
提交回复
热议问题