Need help with mutually included GtkObjects subclasses



Hi, 

I have the following syntax problem whith some objects definition. 
Object A is a "store", it contains some Objects B.
But I want Objects B to know which Object A they are stored in.

So to sum up the structures are:

--- A.h ---
#include "B.h"
typedef struct _A A;
struct _A {
  B *folder;
}
-----------

--- B.h ---
#include "A.h"
typedef struct _B B;
struct _B {
  A *parent_store;
};
-----------

And each header file contains the usual #ifndef A_H ...

The compiler gets rather angry about this, and complains about incomplete
type definitions ....

As you may see, I would not be faced with this problem if the two structures 
were declared in the same header. It would just be a matter of putting
the two typedefs before the struct definitions.

I came up with a rather inelegant trick, but I would like to know if some
C gurus knows some magic declaration to avoid the error.
(like the "class A;", in C++ or Objective C)

The code is available in CVS:gnome-mailer/camel
and the header files are camel-folder.h and camel-store.h

I have joined parts of the headers if the problem as explained above is not 
clear. You can also see the bad trick that made the compiler happy.

Thanks in advance,

Bertrand 

PS: I know there would be ways to avoid this mutual inclusion, but I am 
particularly interested to know the official syntactic way to declare such
a beast.




---- camel-folder.h ----
#include "camel-store.h"


#ifndef CAMEL_FOLDER_DEF
#define CAMEL_FOLDER_DEF 1
typedef struct _CamelFolder CamelFolder;
#endif /* CAMEL_FOLDER_DEF */

#ifndef CAMEL_STORE_DEF
#define CAMEL_STORE_DEF 1
typedef struct _CamelStore CamelStore;
#endif /* CAMEL_STORE_DEF */




struct _CamelFolder
{
	GtkObject parent_object;

	CamelStore *parent_store;
	
};
 .....



---- camel-store ----
#include "camel-folder.h"
#include "camel-service.h"


#ifndef CAMEL_FOLDER_DEF
#define CAMEL_FOLDER_DEF 1
typedef struct _CamelFolder CamelFolder;
#endif /* CAMEL_FOLDER_DEF */

#ifndef CAMEL_STORE_DEF
#define CAMEL_STORE_DEF 1
typedef struct _CamelStore CamelStore;
#endif /* CAMEL_STORE_DEF */

struct _CamelStore
{
	CamelService parent_object;	
	gchar separator;
};



typedef struct {
	CamelServiceClass parent_class;

	void (*set_separator) (CamelStore *store, gchar sep);
	gchar (*get_separator) (CamelStore *store);
	CamelFolder * (*get_folder) (CamelStore *store, GString *folder_name);
	CamelFolder * (*get_root_folder) (CamelStore *store);
	CamelFolder * (*get_default_folder) (CamelStore *store);

} CamelStoreClass;

.....




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]