pass by value : Function parameter « Function « Visual C++ .NET






pass by value

 

#include "stdafx.h"
using namespace System;

ref struct R
{
   R()
   {
      val = 1;
   }

   // copy constructor
   R( R% r)
   {
      val = r.val;
   }

   property int val;
};

void f(R r_local)
{
   r_local.val = 2;
   Console::WriteLine("Within f: " + r_local.val);
}

int main()
{
    R r;
    f(r);
    Console::WriteLine("Outside f: " + r.val);

    R^ rhat = gcnew R();
    f(*rhat);  
    Console::WriteLine("Outside f: " + rhat->val);
}

   
  








Related examples in the same category

1.Passing value struct to function
2.parameter passing
3.pass by reference
4.param array parameter
5.Passing array as parameter