incomplete type error despite complete definition
Hello,
i'm frustrating a bit with the following errors and warnings. Despite including the right header properly (at least i hope so), the compiler is complaining about incomplete/undefined types. There should also be no semicolons missing. The error messages, here you go, great thanks for all help:
cyear.h: In destructor ‘cyear::~cyear()’:
cyear.h:52: warning: possible problem detected in invocation of delete operator:
cyear.h:52: warning: invalid use of undefined type ‘struct cmonth’
cyear.h:12: warning: forward declaration of ‘struct cmonth’
cyear.h:52: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
cyear.h: In member function ‘bool cyear::read_months()’:
cyear.h:65: error: invalid use of undefined type ‘struct cmonth’
cyear.h:12: error: forward declaration of ‘struct cmonth’
You may be interested in the code, too:
cyear.h - critical parts are marked
Code:
#ifndef CYEAR_H
#define CYEAR_H
#include <iostream>
using std::cout;
using std::endl;
#include <list>
using std::list;
#include "cmonth.h"
class cmonth;
struct syear{
short int events;
char main_event[256];
};
struct sweek{
short int events;
char main_event[256];
};
struct sday{
short int events;
char main_event[256];
};
struct stime{
short int hour;
short int minute;
char event[256];
};
class cyear{
private:
int year;
list<cmonth*> cmonths;
syear this_year;
public:
cyear(int _year): year(_year){
furz hallo();
if(!read_year(year, this_year)){
this_year.events = 0;
strcpy(this_year.main_event, "");
}
}
~cyear(){
while(!cmonths.empty()){
delete cmonths.back();
cmonths.pop_back();
}
}
bool read_year(int _year, syear& the_year);
void write_year(int _year, syear& the_year);
void write_year(){
write_year(year, this_year);
}
bool read_months(){
for(int i = 1; i < 13; i++){
cmonths.push_back(new cmonth(i, *this));
}
}
int get_year(){ return year; };
void set_event(char event[]);
void inc_events(){ this_year.events++; }
void print();
static bool is_leap_year(int _year);
bool is_leap_year(){ is_leap_year(year); }
static int doomesday(int _year){
return (2 + _year + (_year/4) - (_year/100) + (_year/400))%7;
}
int doomesday(){ doomesday(year); }
friend class cmonth;
};
#endif
...and cmonth.h
Code:
#ifndef CMONTH_H
#define CMONTH_H
#include "cyear.h"
#include "cweek.h"
#include "cday.h"
#include <iostream>
using std::cout;
using std::endl;
#include <list>
using std::list;
struct smonth{
short int events;
char main_event[256];
};
class cyear;
#include "cyear.h"
class cmonth{
private:
int month;
list<cweek*> cweeks;
list<cday*> cdays;
smonth this_month;
cyear& the_year;
public:
cmonth(int _month, cyear& _the_year): month(_month),
the_year(_the_year){
if(!read_month(month, this_month)){
this_month.events = 0;
strcpy(this_month.main_event, "");
}
}
~cmonth(){
}
bool read_month(int _month, smonth& the_month);
void write_month(int _month, smonth& the_month);
void write_month(){
write_month(month, this_month);
}
void set_event(char event[]);
void inc_events(){ this_month.events++; }
void print();
};
#endif
If something is unclear, please ask, I know that it is a lot code for a post.