Why isn't the compiler able to promote char
to int&
but has no problem when passing it by reference-to-const (char
to int const&
)?
Example code:
#include <iostream>
using namespace std;
void func1(int & i) { cout << "int & " << i << endl; }
void func2(int const & i) { cout << "const int & " << i << endl; }
int main() {
char mychar = 'a';
func1(mychar); // compiler-error
func2(mychar); // no error
return 0;
}