1

I know I will kick myself but I cant see the issue...

I keep getting the error /usr/local/awdn/alucard/include/DateTimeConvert.h:12:17: error: ‘DateTimeParse’ has not been declared

but it is included. what am I not seeing?

#ifndef DATETIMECONVERT_H
#define DATETIMECONVERT_H

#include "TimeZoneSpec.h"
#include "DateTimeParse.h"
#include <vector>
#include <string>

class DateTimeConvert
{
public:
  int _to_epoch(DateTimeParse dtp, TimeZoneSpec tzdb);
  int _get_weekday_int(DateTimeParse dtp) {return _zeller(dtp);};
  std::string _get_weekday_abbr(DateTimeParse dtp) {return WEEKDAY_ABBR[_zeller(dtp)];};
  std::string _get_weekday_full(DateTimeParse dtp) {return WEEKDAY_FULL[_zeller(dtp)];};
  int _get_month_to_day(int month) {return MONTH_TO_DAY[month];};
  int _zeller(DateTimeParse dtp);
private:
  const int MIN_TO_SEC = 60;
  const int HOUR_TO_SEC = 3600;
  const int DAY_TO_SEC = 86400;
  const int EPOCH_YEAR = 1970;
  const int YEAR_TO_DAY = 365;
  const std::vector<int> MONTH_TO_DAY = {31,28,31,30,31,30,31,31,30,31,30,31};
  const std::vector<int> ZELLER_MONTH_TABLE = {13,14,3,4,5,6,7,8,9,10,11,12};
  const std::vector<std::string> WEEKDAY_ABBR = {"Sat","Sun","Mon","Tue","Wed","Thu","Fri"};
  const std::vector<std::string> WEEKDAY_FULL = {"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
};

#endif

DateTimeParse.h:

#ifndef DATETIMEPARSE_H
#define DATETIMEPARSE_H

#include "TimeZoneSpec.h"
#include "DateTimeFormat.h"
#include "DateTimeConvert.h"
#include <string>
#include <map>
#include <vector>

class DateTimeParse
{
public:
  DateTimeParse();
  void _parse(std::string inDateTime, std::string inFormat);
  bool _is_dst(DateTimeConvert dtc, TimeZoneSpec tzs);
  bool _is_leapyear();;
  int _get_year() {return m_year;}
  void _set_year(int year) {m_year = year;};
  int _get_month() {return m_month;};
  void _set_month(int month) {m_month = month;};
  int _get_day() {return m_day;};
  void _set_day(int day) {m_day = day;};
  int _get_hour() {return m_hr;};
  void _set_hour(int hr) {m_hr = hr;};
  int _get_min() {return m_min;};
  void _set_min(int min) {m_min = min;};
  int _get_sec() {return m_sec;};
  void _set_sec(int sec) {m_sec = sec;};
  std::string _get_tz() {return m_tz;};
private:
  void _parsepart(std::string inDateTime, std::string inFormat);
  std::map<std::string,DateTimeFormat> m_map;
  const std::map<std::string,std::vector<int> > m_ftz = {{"Z", {3,0,0}}};
  int m_year = 0;
  int m_month = 0;
  int m_day = 0;
  int m_hr = 0;
  int m_min = 0;
  int m_sec = 0;
  std::string m_tz = "CST";
};

#endif
user207421
  • 305,947
  • 44
  • 307
  • 483
deadpickle
  • 115
  • 2
  • 15

1 Answers1

2

You have a circular include.

You have header file A including header file B, and header file B including header A.

The second time header file A is included, it sees that its ifndef/define guard is already set, and preprocesses to an empty file.

Then the compiler resumes reading header file B, sees a reference to a class that's defined in header file A, but up to this point it is yet to actually read it, and tells you that you're doing it wrong.

You need to explicitly add forward declarations to your header files.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148