Sign in to follow this  
pascalosti

My value wont hold..... managed code

Recommended Posts

The prob is at the end of the code, after i call my function, it doesnt keep the value.
//struct
value struct Vehicle{
public:
	int ^VIN;
	String ^Model;

// function to assign value
void Intro(Vehicle ^A){

	Console::WriteLine("Type 0 if info is not available!");

	Console::WriteLine("Enter VIN Number:");
	String ^tmp = Console::ReadLine();
	A->VIN = Convert::ToInt32(tmp);


// main
// create 2 vehicle types, and initialize (tmp to junk array)

array<Vehicle> ^junk = gcnew array <Vehicle> (Array_Size);

	Vehicle ^tmp;
	tmp = gcnew Vehicle;
	tmp->Tech = gcnew TechInfo;

        tmp->VIN = nullptr;
	tmp->Model = nullptr;

for(int i = 0; (Array_Size-1) > i; i++)
	{
		junk[i] = *tmp;}
        // assign new value to junk
        Intro(junk[0]);
         // here is the problem
        // when i print the value it just prints the initialization value
        // not the new value from the function
	Console::WriteLine(L"Value of VIN is: {0}", junk[0].VIN);



Share this post


Link to post
Share on other sites
I don't know anything about managed code, but are you positive you're passing the Vehicle into Intro by reference? You store it in the array using *tmp, which gets the value, so I'm thinking you would be passing a copy of the Vehicle in (pass by value), rather than pass by reference.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this