In your code, the first step is to #include the needed headers: depending
on your header include strategy, this can be as simple as
#include "maman-bar.h"
or as complicated as tens
of #include lines ending with #include "maman-bar.h"
:
/*
* Copyright information
*/
#include "maman-bar.h"
/* If you use Pimpls, include the private structure
* definition here. Some people create a maman-bar-private.h header
* which is included by the maman-bar.c file and which contains the
* definition for this private structure.
*/
struct _MamanBarPrivate {
int member_1;
/* stuff */
};
/*
* forward definitions
*/
Call the G_DEFINE_TYPE
macro using the name
of the type, the prefix of the functions and the parent GType to
reduce the amount of boilerplate needed. This macro will:
- implement the
maman_bar_get_type
function
- define a parent class pointer accessible from
the whole .c file
G_DEFINE_TYPE (MamanBar, maman_bar, G_TYPE_OBJECT);
It is also possible to use the
G_DEFINE_TYPE_WITH_CODE
macro to control the
get_type function implementation - for instance, to add a call to
G_IMPLEMENT_INTERFACE
macro which will
call the g_type_implement_interface
function.