Accessing the [] operator from a pointer

前端 未结 7 698
北海茫月
北海茫月 2020-11-30 02:52

If I define a pointer to an object that defines the [] operator, is there a direct way to access this operator from a pointer?

For example, in the follo

7条回答
  •  春和景丽
    2020-11-30 03:44

    People are advising you to use ->at(0) because of range checking. But here is my advise (with other point of view):

    NEVER use ->at(0)! It is really slower. Would you sacrifice performance just because you are lazy enough to not check range by yourself? If so, you should not be programming in C++.

    I think (*VecPtr)[0] is ok.

提交回复
热议问题