类内通过去const来实行修改内容
#include <stdio.h>
class A
{
public:
A():m_width(0), m_height(0)
{
}
void create()
{
*(const_cast<int*> (&m_width)) = 10;
*(const_cast<int*> (&m_height)) = 100;
}
public:
const int m_width;
const int m_height;
};
int main()
{
A a;
a.create();
printf("%d %d\n", a.m_width, a.m_height);
a.m_width = 10;
}