jeudi 10 août 2017

Why is my extern const double incompatible with double function parameter, but my extern const int is compatible with int function parameter?

I have a set of constants defined in a separate .cpp file and included into main through a header. One constant is a const double and another is a const int. In main I have a function that takes two doubles as parameters and another that takes two integers. When I pass my integer-constant into the integer function it works fine, but when I try to pass my double-constant into the double function it causes an error that says: 'argument of type "const double (*)()" is incompatible with parameter of type "double"'.

Constants.cpp

namespace Constants
{
    extern const double d_const(100.0);
    extern const int i_const(20);
}

Constants.h

namespace Constants
{
    extern const double d_const;
    extern const int i_const;
}

main.cpp

#include "Constants.h"

double d_function(double parameter_1, double parameter_2)
{
    // Function body
}

int i_function(int parameter_1, int parameter_2)
{
    // Function body
}

i_function(0, Constants::i_const);    // Works.
d_function(0.0, Constants::d_const);  // Error.

Why does it work with integers but not with doubles?

Aucun commentaire:

Enregistrer un commentaire