const与引用
发布日期:2021-06-29 04:13:04 浏览次数:2 分类:技术文章

本文共 497 字,大约阅读时间需要 1 分钟。

const变量可以是const变量和其他任何类型的引用,但是非const只能引用与自己类型相同的变量,如下

#include
using namespace std;int main(){ const int a=100; const int &b=a; //正确cout<
<
<
<

 

#include
using namespace std;int main(){int a=100;const int &b=a; //正确cout<
<
<
<

 

#include
using namespace std;int main(){ const int &a=10; //正确 cout<
<
#include
using namespace std;int main(){const int a=100; int &b=a; //错误cout<
<
<
<

 

转载地址:https://blog.csdn.net/zh634455283/article/details/7716234 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:typeid与typedef
下一篇:举足轻重的extern

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月14日 04时54分29秒