Can't figure out why I'm getting this error

I was given code I was supposed to run for class but I get this error every time.
Undefined symbols for architecture x86_64:
"Date::Date(int, int, int)", referenced from:
_main in DateDriver-2fbcc2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am using Visual Studio Code, so could that be the problem (though other people in class said it ran for them just fine)?

Code for Date.h header file
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

class MonthError
{};
class DayError
{};

class YearError
{};
class Date
{
public:
  Date();
  Date(int initMonth, int initDay, int initYear);
  // Knowledge Responsibilities
  int GetMonth() const;
  int GetDay() const;
  int GetYear() const;
  bool operator<(const Date& otherDate) const;
  bool operator>(const Date& otherDate) const;
  bool operator==(const Date& otherDate) const;
private:
  int month;
  int day;
  int year;
};

***************************************
***************************************

The DateDriver.cpp file where I'm getting the error

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
#include <iostream>
#include "Date.h"

using namespace std;

int main() 
{
  int month;
  int day;
  int year;
  
  cout << "Enter month. Negative month stops test." << endl;
  cin >> month;
  while (month >=  0)
  {
    cout << "Enter day and year" << endl;
    cin >> day >> year;
    try
    {
      Date date1(month, day, year);
	  cout << "Valid date." << endl;
	}
    catch (MonthError error)
    {
      cout << "Attempt to create date with invalid month." << endl;  
	}
	catch (DayError error)
	{
	  cout << "Attempt to create date with invalid day." << endl;
	}
	catch (YearError error)
	{
	  cout << "Attempt to create date with invalid year." << endl;
	}
	cout << "Enter month.  Negative month stops test." << endl;
	cin >> month;
  }
  return 0;
}  	

Last edited on
You declared a constructor Date(int,int,int) on line 13 in Date.h:
Date(int initMonth, int initDay, int initYear);

You called a constructor Date(int,int,int) on line 20 in DateDriver.cpp:
Date date1(month, day, year);

You just never got around to writing the function!
Topic archived. No new replies allowed.