For a c++ rookie this syntax may look interesting ..
void myFunc() const;
Normally we love to see const at the beginning of a line . like "const int i = 10;". Actually above line is perfect. It tells that the function can't modify it's calling object. It is referred as read only function in some text books. It can call some more constant functions from inside. But it can't call any normal function. This type of functions can be called from any ordinary functions as well as constant functions.
Suppose you want to declare a constant function, but at the same time you want it to modify some particular data. In that case you need to use mutable key word while declaring your variables.
mutable int x;
void myFunc() const;
Normally we love to see const at the beginning of a line . like "const int i = 10;". Actually above line is perfect. It tells that the function can't modify it's calling object. It is referred as read only function in some text books. It can call some more constant functions from inside. But it can't call any normal function. This type of functions can be called from any ordinary functions as well as constant functions.
Suppose you want to declare a constant function, but at the same time you want it to modify some particular data. In that case you need to use mutable key word while declaring your variables.
mutable int x;
No comments:
Post a Comment