Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
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.

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%()
}

Community Additions

ADD
Show:
© 2015 Microsoft