【发布时间】:2016-03-19 11:18:20
【问题描述】:
为什么编译器不能将char 提升为int&,但通过引用到常量(char 到int const&)传递它时没有问题?
示例代码:
#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;
}
【问题讨论】:
标签: c++ type-conversion pass-by-reference overloading integer-promotion