I cannot make out why am I getting this error: undefined reference to DayOfYear::DayOfYear()

My program compiles OK!
but when I run it I get this error:
undefined reference to DayOfYear::check_date()
undefined reference to DayOfYear::DayOfYear()

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
92
  //Program to demonstrate the function equal. The class DayOfYear
//is the same as in self-Test Exercise 23-24 in Chapter 10.
#include<iostream>

using namespace std;

class DayOfYear
{
public:
	DayOfYear(int the_month, int the_day);
	//Precondition:the_month and the_day form a
	//possible date. Initializes the date according to the arguments
	
	DayOfYear();
	//Initializes the date to January first.
	
	void input();
	
	void output();
	
	int get_month();
	//Returns the month, 1 for January, 2 for February, etc.
	
	int get_day();
	//Returns the day of the month;
private:
	void check_date();
	int month;
	int day;
};

bool equal(DayOfYear date1, DayOfYear date2);
//Precondition: date1 and date2 have values.
//Returns true if date1 and date2 represent the same date;
//otherwise , returns false.

int main()
{
	DayOfYear today, bach_birthday(3, 21);
	
		cout << "Enter today's date:\n";
	today.input();
	cout << "Today's date is: ";
	today.output();
	
	cout << "J. S. Bach's birthday is ";
	bach_birthday.output();
	
	if ( equal(today, bach_birthday))
		cout << "Happy Birthday Johann Sebastian\n";
	else
		cout << "HappyUnbirthday Johann Sebastian\n";
	
	return 0;
}

bool equal(DayOfYear date1, DayOfYear date2)
{
	return (date1.get_month() == date2.get_month() &&
				date1.get_day() == date2.get_day() );
}

DayOfYear::DayOfYear(int the_month, int the_day)
					: month(the_month), day(the_day)
{
	check_date();
}
int DayOfYear::get_month()
{
	return month;
}

int DayOfYear::get_day()
{
	return day;
}

//Uses iostream
void DayOfYear::input()
{
	cout << "Enter the month as a number: ";
	cin >> month;
	cout << "Enter the day of the month: ";
	cin >> day;
}

//Uses iostream
void DayOfYear::output()
{
	cout << "month = " << month
	     << ", day = " << day << endl;
}
Hehe, it seems I know why. You have defined "check_date()" in the head, but you didn't describe it below. That's why the program first complains about check_date() first and then about the other function although it is declared.
I wonder why the compiler doesn't complain that function is not defined completely, normally you should get a undefined symbol error...
Thanks olfibits!!! I have defined both of those undefined errors and the program runs like a first class.
Glad I could help :)
Have a nice Christmas time and fun with C++ programming
@Bopaki

Just a thought to help you out a bit:

Do you use an IDE? If so, you should be able to get it to automatically make a function stub for each function you declare. Usually there is a menu option to make a new class, this creates a separate header file and cpp file in the project. Once you type a new function declaration in the class, there should be some way of getting the system to make a function stub for it in the cpp file. That way you won't forget to define any of the functions.

Good Luck !!
Topic archived. No new replies allowed.