【发布时间】:2015-06-14 17:05:10
【问题描述】:
你能在下面的代码中解释一下原因吗:
#include <iostream>
void fun(char * const & x){(*x)++;}
int main(){
char txt[100]="kolokwium";
fun(txt);
std::cout << txt <<"\n";
}
代码编译需要关键字 const 吗?
如果我删除它,我会得到:
invalid initialization of non-const reference of type ‘char*&’ from an rvalue of type ‘char*’
谢谢!
【问题讨论】:
标签: c++ constants pass-by-reference