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: Overload Functions with Interior Pointers and Native Pointers

Functions can be overloaded depending on whether the parameter type is an interior pointer or a native pointer.


// interior_ptr_overload.cpp
// compile with: /clr
using namespace System;

// C++ class
struct S {
   int i;

// managed class
ref struct G {
   int i;

// can update unmanaged storage
void f( int* pi ) {
   *pi = 10;
   Console::WriteLine("in f( int* pi )");

// can update managed storage
void f( interior_ptr<int> pi ) {
   *pi = 10; 
   Console::WriteLine("in f( interior_ptr<int> pi )");

int main() {
   S *pS = new S;   // C++ heap
   G ^pG = gcnew G;   // common language runtime heap
   f( &pS->i );
   f( &pG->i );


in f( int* pi )
in f( interior_ptr<int> pi )

See Also



Community Additions

© 2015 Microsoft