开发者

Why operator () [] -> = must be non-static member? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Why are some operators in C++ only allowed to be overloaded as member functions?

Why operator () [] -> = must be non-static member? Why it can开发者_C百科't be friend?


Because you have to call it on an instance of a class. Take for example the -> operator. How would you propose getting a pointer to the class itself? It doesn't make much sense.


Because it has to be non-static. Simple design decision. Probably because C++ doesn't have the concept of class objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜