开发者

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

开发者 https://www.devze.com 2023-01-29 09:13 出处:网络
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?
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

精彩评论

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