Cannot assign member data

Can anyone tell me why I cannot assign the data to the members in class?\
Those underline parts are red on the line in compiler.

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
  # include <iostream>
# include <iomanip>
# include <cstring> //Do I need this for strcpy?
using namespace std;

const int SIZE = 51;

class MovieData
{
	char title[SIZE];
	char director[SIZE];
	int year;
	int length;
	double prodCost;
	double firstYearRev;
};

void displayMovie(MovieData);

int main()
{
	MovieData movie1;

	strcpy(movie1.title, "War of the Worlds");
	strcpy(movie1.director, "Byron Haskin");
	movie1.year = 1953;
	movie1.length = 88;
	movie1.prodCost = 15000000.0;
	movie1.firstYearRev = 28000000.0;
}
Last edited on
Members of a class are private by default (i.e. cannot be accessed from outside the class).

So you either need to specify that the members are public:
1
2
3
4
class MovieData
{
   public:
   ...


or define MovieData as a struct, which is the same as a class, but the members are public by default.
Topic archived. No new replies allowed.