Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Calling objects that are created outside the main from the main.

$
0
0
Hey guys,

I cannot for the life of me figure out how to call an object in the main. The object that needs to be used must be made available throughout the program, but is only accessible in the function that created it.
I've looked up a series of different solutions, but none of them fit my needs.

Here's the code.


void createVehicleDB()
{
	int numberLines = 0; 

	ifstream fi; 
	fi.open("vehicles.txt");
	fi >> numberLines;

	VEHICLE * vehicle = new VEHICLE[numberLines]; //all vehicle objects are only accessible in createVehicleDB()  :(/>
	
        ....
	
	fi.clear(); //clear file stream
	fi.close(); //close file stream

}

void main()
{
	createVehicleDB();

	mainMenu();

	cout << vehicle[0].model; // Need to be able to call this.
}




Any help would be appreciated. Thank you!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>