Class problems

Hello, I'm having some problems with solving something in C++. Right here is an example:
Say I have some header file named Book.h with a class Book defined it it and with some methods with a parameter, whose type is another class, named Author (define in Author.h), for example. Like so:
Book.h
1
2
3
4
5
6
#include "Author.h"

class Book {
   setFirstAuthor(Author*)
   setSecondAuthor(Author*);
};


and

Author.h
1
2
3
4
5
#include "Book.h"

class Author {
   setFirstBookWritten(Book*);
};


I know this is not a very good example. But I just needed to recreate the situation. In my actual project, I use this to apply the MVC pattern to my code, were Book is a baseclass as an Obeservable and Author is an interface for an Observer.

But to the point:
now I of course get the message: "(Book.h) Author is not defined... etc"
How do I solve this?

Many thanks!!!!!
Last edited on
Use either

1
2
3
4
5
6
class Author;

class Book {
   setFirstAuthor(Author*)
   setSecondAuthor(Author*);
};


or

1
2
3
4
class Book {
   setFirstAuthor( class Author*)
   setSecondAuthor(class Author*);
};


in book.h (excluding #include "Author")

Or you can define a third header that will contain declarations

class Book;
class Author;

and include it in these two headers.
Topic archived. No new replies allowed.