How to link files?

HI!
My question is a little off topic and that's I don't know what should I do to write complicated programs.
I used to write programs that had only main.cpp and some .h's , but as I moved into classes, they told me you should write each class in two files, one .h and one .cpp .
Now It got a little complicated and some structs don't know classes and vice versa.
Here what i've done : (Please take a look at it)

main.cpp :
1
2
3
4
5
6
7
8
9
10
#include "Calender.h"

int main ()
{
    Calender user ;
    user = user.getDate () ;
    user.showDate (user) ;
    user = user.DayPP (user) ;
    user = user.DayMM (user) ;
}


Calender.h :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef CALENDER_H_INCLUDED
#define CALENDER_H_INCLUDED

#include "Date.h"

class Calender
{
public :
    Calender getDate () ;
    void showDate (Calender) ;
    Calender DayPP (Calender) ;
    Calender DayMM (Calender) ;
    Date addDate () ;
private :
    short day , month , year ;
} ;

#endif // CALENDER_H_INCLUDED 


Calender.cpp :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <conio.h>

using std :: cout ;
using std :: cin ;

#include "Calender.h"

Calender Calender :: getDate ()
{
     //Function declaration
}

void Calender :: showDate (Calender show)
{
     //Function declaration
}

Calender Calender :: DayMM (Calender input)
{
     //Function declaration
}


Date.h :
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef DATE_H_INCLUDED
#define DATE_H_INCLUDED

#include "Calender.h"

struct Date
{
    char Name [10] ;
    Calender Date ;
} ;

#endif // DATE_H_INCLUDED 


Now my problem is that in Date.h an error appears :
Calender doesn't name a type

BUT I included Calender.h in the beginning.
In my last project I faced such errors too and still I don't understand how it works and what should I exactly do.
I searched internet but I couldn't find a toturial, if you know any documentation on how to create files and link them to each other please let me know.
thanks in advanced
The problem may well be that you have circular dependencies. "Date.h" includes "Calender.h", and "Calender.h" includes "Date.h".

Do a Google search for "c++ circular dependency" for some articles on how to resolve it.

Also, that's not how you spell calendar :P
http://www.cplusplus.com/forum/articles/10627/ (4)


By the way
1
2
3
4
    user = user.getDate () ;
    user.showDate (user) ;
    user = user.DayPP (user) ;
    user = user.DayMM (user) ;
When you call a member function, the object used is passed as a hidden parameter, the this pointer.
Last edited on
Topic archived. No new replies allowed.