Array outside of class.

(Line 60) I get an error telling me an array cannot be initialized without a parenthesized intializer. What am i doing wrong? can someone please help? Thanks

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
class movie {
private: string name;
private: string date;
private: string cost;
private: string gross;

		 //Takes name,date of release, production costs, and gross profit
public: movie(string d, string n, string c, string g)
{
	date = d;
	name = n;
	cost = c;
	gross = g;
}

public: string getName()
{
	return name;
}

public: string getDate()
{
	return date;
}

public: string getCost()
{
	return cost;
}

public: long convertGross()
{
	//converts gross profit to an integer so that it can be sorted correctly
	string temp;
	int i = 0;
	while (gross[i] != 0)
	{
		if (gross[i] != ',' && gross[i] != '$')
			temp += gross[i++];
		else
			i++;
	}
	const char * c = temp.c_str();
	long num = atol(c);
	return num;
}

public: string getGross()
{
	return gross;
}

		//Displays movie information to the user
public: void displayInfo()
{
	cout << "Date: " << date << " " << "Name: " << name << "Production Cost: " << cost << "Gross: " << gross << endl;
}
};

movie m[99] =  movie("", "", "", "") ;
Last edited on
What am i doing wrong?

That depends on what you're trying to do.
Line 60: You're trying to initialize an array of 99 objects of type "movie" by assigning it only a single "movie" object. You need an array on right hand side of the assignment operator.

1
2
// Initialize all elements of array `m´
movie m[99] =  { movie("", "", "", ""), movie("", "", "", ""), movie("", "", "", ""),  /* Repeat up too 99 times */};


or define a "movie" default constructor and define

1
2
// Initialize all elements of array `m´ with default values
movie m[99];

Topic archived. No new replies allowed.