Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't a Visual C++ interface contain operators?

As per the MSDN doc on __interface, a Visual C++ interface "Cannot contain constructors, destructors, or operators."

Why can't an interface contain an operator? Is there that much of a difference between a get method that returns a reference:

SomeType& Get(WORD wIndex);

and the overloaded indexer operator?

SomeType& operator[](WORD wIndex);
like image 557
iano Avatar asked Dec 29 '22 06:12

iano


1 Answers

The __interface modifier is a Visual C++ extension to help implementing COM interfaces. This allows you to specify a COM 'interface' and enforces the COM interface rules.

And because COM is a C compatible definition, you cannot have operators, Ctor or Dtors.

like image 166
Christopher Avatar answered Dec 31 '22 20:12

Christopher