const 函数

void testconst() const;

int m_id;
mutable int m_consi;

void Student::testconst() const
{
//    m_id = 1; //报错
//    ++m_id;   //报错
    int i;
    i = 10;

    m_consi = 1;    //不报错
}

 


版权声明:本文为yongwoozzang原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。