operator[]

class testa
{
private:
 struct testb{
  testb(testa& a,int ind):m_ta(a),m_index(ind){}

  testb operator =(int a){
   m_index = a;
   return *this;
  }
 private:
  testb& operator =(const testb& b);
  int m_index;
  testa& m_ta;
 };
public:
 testa(int a)
 {
  m_x = a;
 }
 ~testa(){
  int a;
  a = 0;
 }
 testb operator[](int idx)
 {
  return testb(*this,idx);
 }

private:
 int m_x;
};

int _tmain(int argc, _TCHAR* argv[])
{
 {
  testa ta = 2;;
  ta[0] = 1;
  int a = 0;
  printf("%d/n",a);
 }

 return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章