나는 boost :: gil 소스 코드를보고 있었고이 주석과 해당 코드를 2D 점 클래스에서 발견했습니다.안전 연산자 [] 액세스를위한 멤버 배열에 대한 정적 포인터
const T& operator[](std::size_t i) const { return this->*mem_array[i]; }
T& operator[](std::size_t i) { return this->*mem_array[i]; }
...
private:
// this static array of pointers to member variables makes operator[]
// safe and doesn't seem to exhibit any performance penalty
static T point2<T>::* const mem_array[num_dimensions];
http://www.boost.org/doc/libs/develop/boost/gil/utilities.hpp
질문 :
- 이 정확히 무엇입니까?
- 어떻게하면
operator[]
이 안전할까요?
주석은 "안전"을 정의하지 않기 때문에 그것이 의미하는 바가 무엇인지 또는 어떻게 작동 하는지를 말하는 것은 불가능합니다. 물론, 의도 한대로 ** 추측 할 수 있으며 추측이 암시하는 바가 무엇이든 할 수 있는지에 대한 가설을 세울 수 있습니다. –