Dec 5, 2009 at 10:34am UTC
Hello, I'm having problems passing a vector of structs to a function. What I'm trying to do is create a program that implements of a vector of structs which hold data about an object. Thanks in advance if you can provide any help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <fstream>
//Struct to hold the card values
struct Car
{
std::string CarName;
int CarYear;
int CarNum;
};
//Vector prototype
std::vector<Car> Initialize(std::vector<Car> &MVehicle);
void main()
{
//Instance of struct
std::vector<Car> Vehicle;
//Pass the vector of struct to the function
Vehicle = Initialize(Vehicle);
//Function call
Initialize(Vehicle);
system ("PAUSE" );
}
std::vector<Car> Initialize(std::vector<Car> &MVehicle)
{
return MVehicle;
}
Last edited on Dec 5, 2009 at 10:36am UTC