程序的输出是什么?改变了我对const应用的看法,可以改变const引用所指对象的值。
以下下仅仅是测试,只考虑更改的问题,
#include <iostream>
using namespace std;
class Test
{
public:
Test():a(new int(1)) { }
~Test()
{
delete a;
}
int *a;
};
void Message( const Test &t )
{
cout << ++*t.a << endl;
}
int main()
{
//Handle handle1;
//Handle handle2;
//handle1 = handle2;
Test test;
Message( test );
cout << *test.a << endl;
}