반응형

BLOG main image




class A{

public :

float x,y,z;

A(){

x=3;

y=5;

z=7;

}


operator float*(){

return &x;

}


 // 이부분의 주석만 제거하면 operator float*() 가 아닌 float& operator [] 으로 수행된다, 컴파일러마다 다른지는 확인 않함

/*float& operator [](int index)

{

return *((&x)+index);

}*/


};


int main()

{

A ai;

std::cout<<ai[0];            결과는 3  5  7


return 0;

}

반응형

+ Recent posts