What do u meant by 'mutant' key word? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What do u meant by 'mutant' key word?

How does this mutant key word works?

6th Apr 2019, 5:06 AM
hithardh ksvln
hithardh ksvln - avatar
1 Answer
0
I think you meant 'mutable'. Read the following: class one { private: mutable int count=0; public: void print() const { std::cout<<"Hello world"; ++count; //would give an error if it weren't mutable } }; The method print() is marked const,so it can't modify data members of that class. Now,let's say you want to know how many times a user called print(),how would you do it. You use the keyword mutable when you declare the counter variable,thus you can modify it within const methods of a class.
6th Apr 2019, 5:26 AM
Mensch
Mensch - avatar