is const (c++) optional?

前端 未结 11 641
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 21:06

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 con

11条回答
  •  暖寄归人
    2020-12-11 21:16

    In C++, "const" can a apply to a variable (making it unchangeable) or a function (rendering it unable to change other things).

    My use of "const" is not just to prevent my code from changing my variable. It's to prevent some idiot's code from changing my variable (especially if the idiot is me six months from now) and to prevent my code from changing a critical variable some idiot left exposed (especially if the idiot was me six months ago).

提交回复
热议问题