vendredi 15 juin 2018

Casting NULL to long is not ambigious?

I was trying out an example for the usages of NULL vs nullptr. As NULL can be casted into integral types, it should show ambiguity with the below example, but it isn't !!

It shows ambiguous candidate compile error, if it is unsigned long, but not for signed long.

Could anyone care to explain why !!

#include <iostream>
using namespace std;

// NOTE: 
// "long" or "signed long" is not showing ambiguous candidates
// but "unsigned long" does

void func(long st) {
    cout << "overload func\n";
}

void func(int* ptr) {
    cout << "integer pointer overload func\n";
}

int main() {
    func(NULL);
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire