Cyclic Dependency
- From: Matías Alejandro Torres <torresmat gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Cyclic Dependency
- Date: Sun, 11 Mar 2007 17:09:32 -0300
Hi all, I know that this is not a problem for this list, but i have
asked in other list about this and i haven't had an straight answer.
First of all, I'm using C and the GObject libraries. This is my problem:
I have two Classes: Contact and Category. They both know each other and
uses the functions from the class they depend on. When i try to compile
it gives me this error:
$ gcc -Wall `pkg-config --cflags glib-2.0` `pkg-config --cflags
gobject-2.0` -o testcontacts test-contacts.c contact.c category.c
`pkg-config --libs glib-2.0` `pkg-config --libs gobject-2.0`
In file included from contact.h:32,
from contact.c:26:
category.h:73: error: expected declaration specifiers or ‘...’ before
‘Contact’
category.h:74: error: expected declaration specifiers or ‘...’ before
‘Contact’
In file included from category.h:32,
from category.c:25:
contact.h:61: error: expected specifier-qualifier-list before ‘Category’
contact.h:76: error: expected declaration specifiers or ‘...’ before
‘Category’
contact.h:87: error: expected declaration specifiers or ‘...’ before
‘Category’
contact.h:98: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’
before ‘*’ token
In file included from contact.h:32,
from test-contacts.c:3:
category.h:73: error: expected declaration specifiers or ‘...’ before
‘Contact’
category.h:74: error: expected declaration specifiers or ‘...’ before
‘Contact’
So... Contact does not know Category and viceversa.
What should I do to solve this?
HEADER FILES:
/**********************************************************************/
/**************************** CONTACT.H ****************************/
/**********************************************************************/
#ifndef __CONTACT_H__
#define __CONTACT_H__
#include <glib.h>
#include <glib-object.h>
#include <libintl.h>
#include "support.h"
#include "category.h"
G_BEGIN_DECLS
#define CONTACT_TYPE (contact_get_type ())
#define CONTACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACT_TYPE,
Contact))
#define CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
CONTACT_TYPE, ContactClass))
#define IS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACT_TYPE))
#define IS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
CONTACT_TYPE))
typedef struct _ContactClass ContactClass;
typedef struct _ContactPriv ContactPriv;
typedef struct _Contact Contact;
struct _ContactClass {
GObjectClass __parent_class__;
};
struct _Contact {
GObject __parent__;
ContactPriv * priv;
gint id;
GDate * birthdate;
gchar * firstname;
gchar * lastname;
gchar * email;
gchar * telephone;
gchar * mobile;
gchar * address;
Category * category;
};
GType contact_get_type (void);
/* Instance creation */
Contact* contact_new (void);
Contact* contact_full_new (gchar *firstname,
gchar* lastname,
gchar* telephone,
gchar* mobile,
gchar* address,
gchar* email,
GDate* birthdate,
Category *category);
/* MORE FUNCTIONS */
G_END_DECLS
#endif /* __CONTACT_H__*/
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/************************* CATEGORY.H ******************************/
/**********************************************************************/
#ifndef __CATEGORY_H__
#define __CATEGORY_H__
#include <glib.h>
#include <glib-object.h>
#include <libintl.h>
#include "support.h"
#include "contact.h"
G_BEGIN_DECLS
#define CATEGORY_TYPE (category_get_type ())
#define CATEGORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CATEGORY_TYPE,
Category))
#define CATEGORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
CATEGORY_TYPE, CategoryClass))
#define IS_CATEGORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CATEGORY_TYPE))
#define IS_CATEGORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
CATEGORY_TYPE))
typedef struct _CategoryClass CategoryClass;
typedef struct _Category Category;
typedef struct _CategoryPriv CategoryPriv;
struct _CategoryClass {
GObjectClass __parent_class__;
};
struct _Category {
GObject __parent__;
CategoryPriv * priv;
};
GType category_get_type (void);
/* Instance creation */
Category* category_new (void);
/* Setters */
void category_set_id (Category * category, gint id);
void category_set_name (Category * category, gchar * name);
void category_set_description (Category * category, gchar * description);
/* Getters */
gint category_get_id (Category * category);
const gchar * category_get_name (Category * category);
const gchar * category_get_description (Category * category);
/* Operations */
void category_add_contact (Category * category, Contact * contact);
void category_remove_contact (Category * category, Contact * contact);
GSList * category_get_contacts (Category * category);
gint category_get_num_contacts (Category * category);
G_END_DECLS
#endif /* __CATEGORY_H__*/
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]