c++ const 类型检查
3)防止修改,起保护作用,增加程序健壮性
#include<iostream>
using namespace std;
void f( const int i){
i=10; // error: assignment of read-only parameter ‘i’
cout<<i<<endl;
}
int main(){
f(1);
}
可运行
#include<iostream>
using namespace std;
void f( int i){
i=10; // error: assignment of read-only parameter ‘i’
cout<<i<<endl;
}
int main(){
f(1);
}