C ++ objects and often constant function

#include<iostream>
using namespace std;
class Person {
public:
    void show() const {
        M_B = 200 is ; // add the mutable keyword, a member may be modified in the property declaration constant function 
         // m_A = 100; given, often not allowed to modify the properties of the member functions 
    }
     int m_A;
    mutable int m_B;
};
void Test01 () {
     const the Person P;
     // p.m_A = 100; given, often not allowed to modify the object member attribute 
    p.m_B = 100 ; // a member of the mutable property declarations add keywords, often defined objects can be modified after 
    p.show ();
}
int main () {
    test01(); 
    System ( " pasue " );
     return  0 ;
     // the const member functions plus function often referred
     // before adding objects declared const objects often called
     // often object can only invoke a function often 
}

 

Guess you like

Origin www.cnblogs.com/lyt888/p/12488839.html