Jump to content
  • Advertisement
Sign in to follow this  

My value wont hold..... managed code

This topic is 4449 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The prob is at the end of the code, after i call my function, it doesnt keep the value.
value struct Vehicle{
	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 = *tmp;}
        // assign new value to junk
         // 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!