Last week, my colleague ask me, 'what is the purpose of const in enforcing least privilege in C++?' (referring to formal parameter of function)
At first, i'm quite surprised to heard this term 'least privilege'. But then after googling i found on WIKI that this refers to 'limiting access to resources' or known as 'principle of least privilege'.
So IMHO, in C++, the used of const on formal parameter is to :
1) avoid the function from modifying its parameter's (argument's) value
2) as good indication to simplify programming in object-oriented, since we don't have to go through the whole function to verify that the function don't modify the argument
There are more uses of const in C++. Check your documentation for details. But i lists some of them here:
1) declare constant variable.
2) const on (global) function declaration is to allow the function to access constant variable.
3) const on class method's declaration is to indicate that the function (at least) used class' property(s), but never modifies any of it.
-EOF
Selamat datang. Blog ini mengandungi penulisan dan bahan rujukan berkaitan pengaturcaraan dan penyelidikan yang ingin saya kongsi dengan anda. Semoga bermanfaat. (Nota: Selain teks rumi, blog ini turut mengandungi teks jawi bahasa Melayu)
Subscribe to:
Post Comments (Atom)
-
Sebelum ini saya pernah menulis tentang kenapa kita (masyarakat) perlu menulis bahan-bahan bertulis / rujukan ilmiah ( Rujuk Sini ). Namun d...
-
Sumber : PRPM DBP - Kamus Dewan Edisi Empat Muat turun - (Komp) tindakan memindahkan fail dr stesen komputer utama ke stesen komputer pe...
No comments:
Post a Comment