我知道我会踢自己,但我看不出这个问题......
我一直收到错误 /usr/local/awdn/alucard/include/DateTimeConvert.h:12:17:错误:'DateTimeParse'尚未声明
但它包括在内。我没看到什么?
#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
答案 0 :(得分:2)
你有一个循环包含。
您有包含头文件B的头文件A和包含头A的头文件B.
第二次包含头文件A时,它会看到其ifndef / define guard已经设置,并预处理为空文件。
然后编译器恢复读取头文件B,看到对头文件A中定义的类的引用,但到目前为止它还没有实际读取它,并告诉你你&#39;做错了。
您需要向头文件显式添加前向声明。