jeudi 23 avril 2015

C++ Type Check in Functions ignored (required double, provieded int)

I have the following code

#include <iostream>

using namespace std;

int dmult(int a, int b){
    return 2*a*b;

int main(void)
    double a = 3.3;
    double b = 2;
    int c = dmult(a,b);
    cout << c << endl;
    return 0;

It compiles with MinGW without problems. The result is (as I thought) false. Is it a problem of the compiler, that there is now warning, that a function expecting integers, but is feeded with doubles, can compile without waring that the input type is wrong? Does it mean, C++ ignores the input type of a function. Shouldn't it realise, that the function arguments have the wrong type.

Thanks for the answer!

Aucun commentaire:

Enregistrer un commentaire