In here I'll outline the errors and problems I've discovered about my MSDN magazine article
(which you can read here).
This is one that Martin Lapierre pointed out to me (Thanks Martin!).
As it turns out, there are three Managed Operators that you can't overload from your Managed C++ code:
You would normally define op_True and op_False operators in MC++ like this:
static bool op_True(T * t) { ... }
static bool op_False(T* t) { ... }
specialname
attribute.
The problem with op_LogicalNot, on the other hand, is quite different. The problem is that the
MC++ compiler only recognizes this operator under a name that was used in some of the early .NET betas
and not under the name that the CLR rules dictate. So, if you try declaring it with the name
op_LogicalNot, the MC++ compiler will just treat it as any other static method and generate the normal
metadata associated with it (i.e. not specialname
). The end result is the same as for
op_True and op_False.
The name for op_LogicalNot that the MC++ compiler does recognize is op_Negation, and thus,
if you declare the operator with this name, the compiler will generate the correct signature for a
managed operator, but now, it is the C# compiler which doesn't see the declaration, since it is looking
for a method call op_LogicalNote, which, obviously, doesn't exist.