|
class TextBlock {
public:
...
const char& operator[] (std::size_t position) const {
...
return text[position]; // text is the member var.
}
char& operator[] (std::size_t position) {
return
const_cast<char&> (
static_cast<const TextBlock&> // <- 바로 이부분!!
(*this)[position]
);
}
...
}
위 소스에서 바로 이부분!! 이라고 한 부분-_-이 궁금합니다.
굳이 TextBlock& 인 레퍼런스로 캐스팅을 할 필요가 있느냐 하는건데요,
제가 볼 때는 그냥 TextBlock으로만 해도 아무 문제가 없을 것 같은데,
특별히 이렇게 하는 이유가 있는 건가요? (성능 or 속도 때문인지...)
|