为什么Visual C++接口不能包含运算符?

ian*_*ano 4 c++ interface operator-overloading visual-c++

根据__interface上MSDN doc,Visual C++接口"不能包含构造函数,析构函数或运算符".

为什么接口不能包含运算符?返回引用的get方法之间有多大区别:

SomeType& Get(WORD wIndex);
Run Code Online (Sandbox Code Playgroud)

和重载的索引器操作符?

SomeType& operator[](WORD wIndex);
Run Code Online (Sandbox Code Playgroud)

Chr*_*her 8

__interface修改是一个Visual C++的扩展,以帮助实现COM接口.这允许您指定COM'接口'并强制执行COM接口规则.

而且因为COM是C兼容的定义,所以你不能拥有运营商,Ctor或Dtors.