is const (c++) optional?(const (c++) 是可选的吗?)
问题描述
according to some tutorials i read a while back, the "const" declaration makes a variable "constant" ie it cannot change later.
But i find this const declaration abit inconveniencing since the compiler sometimes gives errors like
"cannot convert const int to int"
or something like that.
and i find myself cheating by removing it anyway.
question: assuming that i am careful about not changing a variable in my source code, can i happily forget about this const stuff?
Thanks in advance
Are you serious? Why would you want to give up on such a useful feature just because you make a mistake sometimes? Better try and learn to avoid mistakes with const and you benefit from the great assistance it adds to ensure correctnes with your code.
Of course, you can say goodbye to all the help the language provides, and tell the compiler thereby not tell you about mistakes in your code anymore. Instead, you will have to ask the debugger later on where your bugs are. Not sure whether that's better.
这篇关于const (c++) 是可选的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:const (c++) 是可选的吗?
基础教程推荐
- 全面了解C语言 static 关键字 2023-03-26
- C语言 详解字符串基础 2023-03-27
- C++实现ETW进行进程变动监控详解 2023-05-15
- [c语言-函数]不定量参数 2023-09-08
- centos 7 vscode cmake 编译c++工程 2023-09-17
- C语言编程C++旋转字符操作串示例详解 2022-11-20
- [C语言]二叉搜索树 2023-09-07
- 带你深度走入C语言取整以及4种函数 2022-09-17
- C++实战之二进制数据处理与封装 2023-05-29
- C语言实现宾馆管理系统课程设计 2023-03-13
