How to: Cannot Use Tracking References and Unary "Take-Address" Operator
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Cannot Use Tracking References and Unary "Take-Address" Operator

The following sample shows that a tracking reference cannot be used as a unary take-address operator.

// tracking_reference_unary.cpp
// compile with: /clr
using namespace System;
ref struct R {
   static R^ operator%(R ^r) {   // C2805 can't declare unary operator%()
      return nullptr;
   }
   static int operator&(R ^r) {  // can declare a unary operator&()
      return 1;
   }
};

int main() {
   int i;
   int* pi1 = &i; // OK: C++ address of operator&()
   int* pi2 = %i; // ERROR: No managed address of operator%()
   int^ hi = %i; // ERROR: No managed address of operator%()
}
Show:
© 2016 Microsoft