???????C++?е?mutable?????
???????????? ???????[ 2015/9/22 11:43:20 ] ????????.NET ???????????
????mutalbe???????????“?????????”????constant????C++?е?const?????????
??????C++?У?mutable?????????const???????????????mutable???ε??????????????????????????????const?????С?
??????????????????????????????????????????????????????????????const??????????Щ????????????const?????????????Щ??????????????????????????????????mutalbe?????Ρ?
?????????????С?????
class ClxTest
{
public:
void Output() const;
};
void ClxTest::Output() const
{
cout << "Output for test!" << endl;
}
void OutputTest(const ClxTest& lx)
{
lx.Output();
}
??????ClxTest????????Output????????????????????????????????????const???
????????OutputTest?????????????????????????lx??Output????????????????????е??????????????????κγ???????????????????const???Ρ?
??????????????????????????????????????????????????????????????????????????????????????const???????Output????????????????????????????????????????????????????????????????Output??const??????????????????mutable??????——????mutalbe?????????????????????????ж??????
??????????????????????
class ClxTest
{
public:
ClxTest();
~ClxTest();
void Output() const;
int GetOutputTimes() const;
private:
mutable int m_iTimes;
};
ClxTest::ClxTest()
{
m_iTimes = 0;
}
ClxTest::~ClxTest()
{}
void ClxTest::Output() const
{
cout << "Output for test!" << endl;
m_iTimes++;
}
int ClxTest::GetOutputTimes() const
{
return m_iTimes;
}
void OutputTest(const ClxTest& lx)
{
cout << lx.GetOutputTimes() << endl;
lx.Output();
cout << lx.GetOutputTimes() << endl;
}
??????????m_iTimes??mutable???Σ?????????????const??????????const???ε????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11