jeudi 28 décembre 2017

Deleting overloaded function. C++11. Call of overloaded ... is ambiguous

There is global function (just example):

void func( int i )
{
    std::cout << i + 100 << std::endl;
}

I assume that calling this function with char argument does not make any sense so I use delete:

void func(char) = delete;

So I expect that following calls should be possible:

func(1);
func(3.1);
func(true);

And call with char argument should be forbiden:

func('a');

But that is not true. When calling func('a') I get as expected:

error: use of deleted function ‘void func(char)’

But during calling func(2.3) I get:

error: call of overloaded ‘func(double)’ is ambiguous

Aucun commentaire:

Enregistrer un commentaire