나는 연산자 오버로드로 클래스 속성에 대한 "액세스 바로 가기"를 구현하려고하지만 작동시키지 못합니다. 심지어 가능할까요?연산자 오버로드로 클래스 속성에 대한 바로 가기에 액세스
내가 뭘하려 :
struct Fruit {
float energy;
float taste;
}
template<typename T>
class Value {
public:
T val;
T& operator->() { return val; }
}
Value<Fruit> apple;
// this work:
apple.val.energy = 0.5f;
cout << apple.val.energy << endl;
// this do not and i want this to work:
apple->energy = 0.5f;
cout << apple->energy << endl;
확신'운용자는>'포인터를 반환 할 필요가 – vu1p3n0x