h文件;
class ZZC
{
public:
ZZC();
virtual ~ZZC();
int& operator[] (int i); //重载"[]"操作符
private:
int myarr[6];
};
Cpp文件;
ZZC::ZZC()
{
int i;
for (i = 0; i < 6; i++)
{
myarr[i] = i + 9;
}
}
ZZC::~ZZC()
{
}
int& ZZC::operator[] (int i) //返回引用,这样才可以对返回值赋值
{
return myarr[i];
}
调用和输出;
void CZkhView::OnDraw(CDC* pDC)
{
CZkhDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CString str1;
ZZC zc1;
str1.Format("%d", zc1[1]);
pDC->TextOut(20, 20, str1);
zc1[4]=160;
str1.