I get an illegal initalization

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
using namespace std;
#include <string>



class Event
{
public:
	
	void setEventData(string eventName, int hour, int minute, int month, int day, int year);
	void printEventData() const;
	Event(string EventName = "Generic Event", int hour = 0, int minute = 0,
		int month = 1, int day = 1, int year = 2000);
private:
	string EventName;
	Time eventTime;
	Date eventDate;
};

class Time
{
public:
	void setTime (int hr, int min);
	void getTime(int &hr, int &min);
	void printTime();
	Time(int hr, int min);
	Time();
private:
	int hour;
	int minute;
};

class Date
{
public:
	void setDate(int = 1, int = 1, int = 2000);
	void  getDate(int &m, int &d, int &y);
	void printDate();
	Date (int month, int day, int year);
	Date();
private:
	int month;
	int day;
	int year;
};

Date::Date(int m, int d, int yr)
{
	int month = m;
	int day = d;
	int year = yr;
}

Date::Date()
{
	month = day = 1;
	year = 2000;
}

void Event::setEventData(string name, int hr, int min, int mon, int day, int yr)
{
	EventName = name;
	eventTime.setTime(hr, min);
	eventDate.setDate(mon, day, yr);
}

void Event::printEventData() const
{
	cout << EventName << " occurs ";
	eventDate.printDate();
	cout << "at ";
	eventTime.printTime();
}

Event::Event(string name, int hour, int minute, int month, int day, int year)
	: eventTime(hour,minute), eventDate(month,day,year)
{ 
	EventName = name;
}

int main()
{
	Event event("New Year's Day", 0,1,1,1,2008);
	event.printEventData();
	cout << endl;
	event.setEventData("Valentine's Day", 12, 15,2, 14, 2010);
	event.printEventData();
	cout << endl;
	return 0;
}


>c:\users\ben\documents\visual studio 2010\projects\learning c++\week3lab_benjamin horne\week3lab_benjamin horne\week3lab_benjamin horne.cpp(77): error C2614: 'Event' : illegal member initialization: 'eventDate' is not a base or member

1>c:\users\ben\documents\visual studio 2010\projects\learning c++\week3lab_benjamin horne\week3lab_benjamin horne\week3lab_benjamin horne.cpp(77): error C2614: 'Event' : illegal member initialization: 'eventTime' is not a base or member

I'd fix line #2 before anything else. Never put a using declaration before an include.

Time and Date need to be defined before the Event class. Did you cut out some error messages for lines 17 & 18?
Thanks for the line 2, yes there were a few more, error messages, but line 77 was the one that had me scratching my head. I did not see that I did not define the two classes.
that's related to pan's reply. you did define the class but after you call it. it would gives you a compile error.

CMIIW
Topic archived. No new replies allowed.