Okay, I've been working on my own version of a Date class and I had it working before but thought I'd try to revise the code a little at a time, after reading "Effective C++: Third Edition" by Scott Meyers
I'll start with the code as I'm not too sure how to explain what I want to do without showing it:
My "Date" class header file:
#include <iostream>
#include <string>
#include <iostream>
#include "dateimpl.h"
using namespace std;
class Date
{
private:
Month thisMonth;
Day thisDay;
Year thisYear;
public:
Date(const Month &m, const Day &d, const Year &y):thisMonth(m), thisDay(d), thisYear(y)
{
thisMonth.getStr();
thisDay.getStr();
}
};
...I left most of the code out, and only posted what's related to the issue I'm having
My "DateImpl" class header file:
#include <iostream>
#include <string>
using namespace std;
class Year
{
public:
int intVal;
Year(int y):intVal(y) {}
};
class Month
{
public:
void getStr();
const int intVal;
const string strVal;
Month(const int m):intVal(m) {}
};
class Day
{
public:
void getStr();
const int intVal;
const string strVal;
Day(int d):intVal(d) {}
};
The getStr() functions in each of the above are independent, as are the variables...they're only pertinent to the Month and Day classes separately depending on what type they are. These functions are necessary to set "strVal" for each class, as there are calculations or conditionals needed to achieve this.
The issue I'm having is...how would I set the "thisMonth" and "thisDay" string values seemlessly within the "Date" class constructor...if possible?
When I try compiling the code above, the error I get is:
CMakeFiles/calendar2.dir/main.cpp.o: In function 'Date':
/home/josh/projects/Calendar2/./src/date.h:41: undefined reference to 'Month::getStr()'
/home/josh/projects/Calendar2/./src/date.h:42: undefined reference to 'Day::getStr()'
How would I achieve what I'm trying to do? Basically, have it so when a new instance of the Date class is created with the Month, Day, and Year initialized within the constructor, also set the Month and Day string values automatically.
Thanks in advance
-Josh