Vector of Objects

I don't understand why I'm getting an invalid syntax error in the following code. To be clear Visual Studio isn't writing out invalid syntax error, I just mean I'm getting the red lines under the code. (See in code, it is below a comment that says error)

I would also like to note I plan on keeping those vectors empty, then just using the push_back function to add vectors as I go.

This is the first time I've ever tried anything with a vector. So any help, preferably in simple as terms as possible, is appreciated!

Thank you.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 #include <iostream>
#include "OvernightPackage.h"
#include "Package.h"
#include "Person.h"
#include "TwoDayPackage.h"
#include <iomanip>
#include <fstream>
#include <vector>


int main(){
	
	std::string Name_S, Address_S, City_S, State_S, ZipCode_S,
				Name_R,Address_R, City_R, State_R, ZipCode_R;
	double Weight, CostPerOunce, flatRateIncrease, tDcostPerOunce;
	char packageType;
	std::ifstream inFile;

	inFile.open("package.txt");
	
	Package *A;
        //Error occurring below

	vector<Package> regularPackages;
	vector<TwoDayPackage> tDPackages;
	vector<OvernightPackage> oNPackages;

	//End of error, area

	while(inFile >> packageType){
		
		inFile >> Weight;
		inFile >> CostPerOunce;
		inFile.ignore();
		getline(inFile, Name_S);
		getline(inFile, Address_S);
		getline(inFile, City_S);
		getline(inFile, State_S);
		getline(inFile, ZipCode_S);
		getline(inFile, Name_R);
		getline(inFile, Address_R);
		getline(inFile, City_R);
		getline(inFile, State_R);
		getline(inFile, ZipCode_R);

		if(packageType == 'P' || packageType == 'p'){
		A = new Package(Name_S, Address_S, City_S, State_S, ZipCode_S,
				Name_R,Address_R, City_R, State_R, ZipCode_R, Weight, CostPerOunce);
		A->printLable();
		}

		if(packageType == 'O' || packageType == 'o'){
		inFile >> flatRateIncrease;
		A = new OvernightPackage(Name_S, Address_S, City_S, State_S, ZipCode_S,
				Name_R,Address_R, City_R, State_R, ZipCode_R, Weight, CostPerOunce, flatRateIncrease);
		A->printLable();
		}

		if(packageType == 'T' || packageType == 't'){
		inFile >> tDcostPerOunce;
		A = new TwoDayPackage(Name_S, Address_S, City_S, State_S, ZipCode_S,
				Name_R,Address_R, City_R, State_R, ZipCode_R, Weight, CostPerOunce,tDcostPerOunce);
		A->printLable();

		}

	}

	system("pause");

	return 0;
}
Last edited on
Vector is part of namespace std. It looks like a scope issue.
Thank you. Yeah I just need to add std:: in front of them. Can't believe I missed that. = P
Last edited on
Topic archived. No new replies allowed.