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/C++编程中const的使用详解 2023-03-26
- C利用语言实现数据结构之队列 2022-11-22
- C语言基础全局变量与局部变量教程详解 2022-12-31
- 详解c# Emit技术 2023-03-25
- C语言 structural body结构体详解用法 2022-12-06
- 一文带你了解C++中的字符替换方法 2023-07-20
- C++中的atoi 函数简介 2023-01-05
- 如何C++使用模板特化功能 2023-03-05
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26
- C++详细实现完整图书管理功能 2023-04-04