Gobject - Inherit (Chinese)

Kai-Feng Chou
Kai-Feng ChouSenior Embedded Specialist APAC at Altera
Gobject
Inherit


          elpam.tw@gmail.com
          elpam@Taiwan, Taipei, 2008
LICENSE
    ●   本投影片授權方式為:
        –   姓名標示─非商業性─相同方式分享 3.0  台灣版
        –   http://creativecommons.org/licenses/by­nc­sa/3.0/tw/




    ●   所有的範例程式皆為 Public Domain




                                           
                                  elpam.tw@gmail.com
About This Slides
    ●   All example was build by (Ubuntu 9.10)
        –   GCC­4.3.4
        –   GLIB­2.22.2




                                   
                          elpam.tw@gmail.com
Agenda

    ●   GObject 's Introduction
    ●   First Gobject Klass
    ●   Inherit




                                   
                          elpam.tw@gmail.com
GObject's Introduction




                   
          elpam.tw@gmail.com
GTK+ (The GIMP Toolkit)
    ●
        GTK+ 最初是 GIMP 的專用開發庫,後來發展為
        Unix­like 系統下開發圖形界面的應用程序的主流
        開發工具之一
        –   相較於 QT 
    ●   GLib/GObject/GDK/GTK  都是為了發展 GIMP
        而產生的,而 GTK+ 2.0 之後將 GLib 與
        GObject 獨立出來讓其他的軟體使用
             –   March 11, 2002

                                      
                             elpam.tw@gmail.com
GLib
    ●
        大部份的程式語言都提供 OO 以及內建方便的演
        算法
    ●   GLib 也提供了基本的資料結構 (Hash/Linked 
        Lists)
    ●   GLib Object System 則提供了簡單的 OO 
        Framework for C



                              
                     elpam.tw@gmail.com
GObject
    ●
        GTK+, Pango  等函式庫裡的物件都繼承了
        GOjbect 而實作
    ●   提供
        –   管理 Construction/ Destruction
        –   property access method 
             ●   不好用 ....
        –   message passing/ signal support


                                     
                            elpam.tw@gmail.com
Before GObject
●
    學習 GObject 最好的管道
         –   Official Documents
         –   Trace Code/ GTK+ 裡頭的數十個範例
●Gobject 因為沒有語法的限制,所以很容易 '' 無意
/ 惡意 '' 的造成 Memory leaking ,所以:
     ●   依造前人留下來的方式使用。 ( 勿異想天開 )
     ●   真正的了解到每一個 Macro 的用法 / 意義,並嘗試展
         開之
                                      
                             elpam.tw@gmail.com
GObject 4­1
     First Klass
    Step By Step




              
     elpam.tw@gmail.com
範例
    ●   maman­bar.{h|c}
    ●   main.c




                                   
                          elpam.tw@gmail.com
Step 1 :定義物件
      ●   maman­bar.h
typedef struct _MamanBar MamanBar;
typedef struct _MamanBarClass MamanBarClass;

struct _MamanBar {                   繼承 GObject
 GObject parent;
  /* instance members */
 int a;
 int b;
};

struct _MamanBarClass {
  GObjectClass parent;
  /* class members */
};
                                        
                               elpam.tw@gmail.com
將 function 與 value 分開
    ●
        在 GObject 的設計裡,與 C++ 最大的概念上的
        不同就是 member function 與 member value
        擺放的位置
        –   maman_bar 放 member value
        –   maman_bar_class 放 member function
    ●   Why?
        –   member value 是每一個物件都要有一份
        –   member function 則是每一個物件都使用同一份
                                    
                           elpam.tw@gmail.com
精確的說
    ●
        class 裡頭放的資料是所有的物件都存取同一份
        –   C++ 的 static member value 
        –   是的, class 裡不一定要放 function point
        –   不是 static member function
    ●   而 base 裡頭放則是各個物件都保存一份




                                     
                            elpam.tw@gmail.com
Step 2 :註冊 GType
      ●   /* maman­bar.c */
                                     請注意:此 Function 為 Singleton ,而此函式只
GType maman_bar_get_type (void)      會 if(){} 裡只會被執行一次
{
   static GType type = 0;
       if (type == 0) {                            將自已所撰寫的 function 填寫於此
              static const GTypeInfo info = {
             /* You fill this structure. */
             };
       type = g_type_register_static (G_TYPE_OBJECT,
                                   "MamanBarType",
                                   &info, 0);
       }
       return type;
}

                                          
                                 elpam.tw@gmail.com
Step 2 :註冊 GType (cont')
type = g_type_register_static (G_TYPE_OBJECT,  "MamanBarType",  &info, 0);


GType      g_type_register_static     (GType                         parent_type,
                                                         const gchar                   *type_name,
                                                         const GTypeInfo            *info,
                                                         GTypeFlags                     flags);

parent_type : Type from which this type will be derived.
type_name : 0­terminated string used as the name of the new type.
info : The GTypeInfo structure for this type.
flags : Bitwise combination of GTypeFlags values.

Returns : The new type identifier.

                                                        
                                             elpam.tw@gmail.com
什麼是 Type ( 形別 )
    ●
        TypeInfo 裡記錄了物件的 Constructor/ 
        Destructor/  記憶體大小及 Parent 為何
    ●   Glib 有實作 Type System ,管理所有的 Type
        –   動態的 , interpreted languages
        –   靜態的 , compiled languages




                                    
                           elpam.tw@gmail.com
typedef struct {
  /* interface types, classed types, instantiated types */
  guint16                   class_size;
  
  GbaseInitFunc             base_init;
  GbaseFinalizeFunc         base_finalize;
  /* interface types, classed types, instantiated types */
  GclassInitFunc            class_init;
  GclassFinalizeFunc        class_finalize;
  gconstpointer             class_data;
  /* instantiated types */
  guint16                   instance_size;
  guint16                   n_preallocs;
  GinstanceInitFunc         instance_init; 
  /* value handling */
  const GtypeValueTable *value_table;
} GTypeInfo;




                                             
                                    elpam.tw@gmail.com
Step 2 :註冊 GType(cont')
      ●
          目前可以填寫的資料

    static const GTypeInfo info = {
      sizeof (MamanBarClass),
      NULL,   /* base_init */
      NULL,   /* base_finalize */
      NULL,   /* class_init */
      NULL,   /* class_finalize */
      NULL,   /* class_data */
      sizeof (MamanBar),
      0,      /* n_preallocs */
      NULL    /* instance_init */
    };


                                               
                                      elpam.tw@gmail.com
Step 3 :撰寫 basic_init
      ●
          也就是 Constructor
static void
maman_bar_init ( MamanBar* self )
{
  self ­> a = 1;
  self ­> b = 2;
}




                                             
                                    elpam.tw@gmail.com
●   Register function pointer into structure

    static const GTypeInfo info = {
      sizeof (MamanBarClass),
      NULL,   /* base_init */
      NULL,   /* base_finalize */
      NULL,   /* class_init */
      NULL,   /* class_finalize */
      NULL,   /* class_data */
      sizeof (MamanBar),
      0,      /* n_preallocs */
      ?????    /* instance_init */
    };


                                               
                                      elpam.tw@gmail.com
Step 4 : use it
      ●   Add print out information in the maman_bar_init
      ●   Please monitor the order of function launched

int main (int argc, char *argv[])
{
        /* this function should be executed first. Before everything  */
        g_type_init();
                                                You can find out the constructor/ type register 
                                                will be launched by this function
        /* Create our object */
        MamanBar *bar = g_object_new (MAMAN_TYPE_BAR, NULL);

        printf(" bar­>a = (%d) bar­>b = (%d)n", bar­>a, bar­>b );
        return 0;
}
                                                 
                                       elpam.tw@gmail.com
GObject 4­2
       Inherit
    Step By Step




              
     elpam.tw@gmail.com
Step 1 : Define SubBar
      ●   Please Notice This Color /* sub­bar.h */



typedef struct _MamanBar MamanBar;
typedef struct _MamanBarClass MamanBarClass;

struct _SubBar {                     繼承 GObject
 MamanBar parent;
  /* instance members */
 int c;
 int d;
};


                                        
                               elpam.tw@gmail.com
Step 2 : Register SubBar's GType
   ●   Please Notice This Color /* sub­bar.c */
GType maman_bar_get_type (void)
{
   static GType type = 0;
       if (type == 0) {
              static const GTypeInfo info = {
                        sizeof (SubBarClass),
                        NULL,   /* base_init */     NULL,   /* base_finalize */
                        NULL,   /* class_init */    NULL,   /* class_finalize */
                        NULL,   /* class_data */  sizeof (SubBar),
                        0,          /* n_preallocs */
                        sub_bar_init  /* instance_init */
              };
       type = g_type_register_static (MAMAN_BAR_TYPE, "SubBarType", &info, 0);
       }
     return type;                                           
}                                                 elpam.tw@gmail.com
Step 3 : Try Casting
    ●   /* main.c */
    ●   When we need to access parent's member 
        value 
                 ((MamanBar*)subbar)­>a,   ((MamanBar*)subbar)­>b 




                                        
                               elpam.tw@gmail.com
Step 4 : ....
    ●   Yes, it's very simple. No trick like previous slide 
    ●   Please monitor the order of function launched




                                    
                           elpam.tw@gmail.com
Conclusion
    ●   The above example show the inheritance 
        implementation by using Gobject.
    ●   Reader can write to child inherit sub­bar, and 
        monitor the timing of constructor. 




                                   
                          elpam.tw@gmail.com
Next
    ●   We''ll talk about Virtual Function later




                                    
                           elpam.tw@gmail.com
1 of 29

Recommended

OOP in C - Virtual Function (Chinese Version) by
OOP in C - Virtual Function (Chinese Version)OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)Kai-Feng Chou
1.6K views19 slides
Introduction to C++ over CLI by
Introduction to C++ over CLIIntroduction to C++ over CLI
Introduction to C++ over CLI建興 王
2.8K views60 slides
認識 C++11 新標準及使用 AMP 函式庫作平行運算 by
認識 C++11 新標準及使用 AMP 函式庫作平行運算認識 C++11 新標準及使用 AMP 函式庫作平行運算
認識 C++11 新標準及使用 AMP 函式庫作平行運算建興 王
3.2K views100 slides
C python 原始碼解析 投影片 by
C python 原始碼解析 投影片C python 原始碼解析 投影片
C python 原始碼解析 投影片kao kuo-tung
2.1K views48 slides
Intro to C++ Basic by
Intro to C++ BasicIntro to C++ Basic
Intro to C++ BasicShih Chi Lin
686 views29 slides
竞赛中C++语言拾遗 by
竞赛中C++语言拾遗竞赛中C++语言拾遗
竞赛中C++语言拾遗乐群 陈
1.3K views64 slides

More Related Content

What's hot

Java 開發者的函數式程式設計 by
Java 開發者的函數式程式設計Java 開發者的函數式程式設計
Java 開發者的函數式程式設計Justin Lin
2.5K views58 slides
lambda/closure – JavaScript、Python、Scala 到 Java SE 7 by
lambda/closure – JavaScript、Python、Scala 到 Java SE 7lambda/closure – JavaScript、Python、Scala 到 Java SE 7
lambda/closure – JavaScript、Python、Scala 到 Java SE 7Justin Lin
2K views52 slides
Golang 入門初體驗 by
Golang 入門初體驗Golang 入門初體驗
Golang 入門初體驗政斌 楊
1.9K views65 slides
Golangintro by
GolangintroGolangintro
Golangintro理 傅
3.7K views63 slides
Python&GUI by
Python&GUIPython&GUI
Python&GUILeo Zhou
365 views62 slides
第4章函数 by
第4章函数第4章函数
第4章函数summerfeng
294 views53 slides

What's hot(20)

Java 開發者的函數式程式設計 by Justin Lin
Java 開發者的函數式程式設計Java 開發者的函數式程式設計
Java 開發者的函數式程式設計
Justin Lin2.5K views
lambda/closure – JavaScript、Python、Scala 到 Java SE 7 by Justin Lin
lambda/closure – JavaScript、Python、Scala 到 Java SE 7lambda/closure – JavaScript、Python、Scala 到 Java SE 7
lambda/closure – JavaScript、Python、Scala 到 Java SE 7
Justin Lin2K views
Golang 入門初體驗 by 政斌 楊
Golang 入門初體驗Golang 入門初體驗
Golang 入門初體驗
政斌 楊1.9K views
Golangintro by 理 傅
GolangintroGolangintro
Golangintro
理 傅3.7K views
Python&GUI by Leo Zhou
Python&GUIPython&GUI
Python&GUI
Leo Zhou365 views
第4章函数 by summerfeng
第4章函数第4章函数
第4章函数
summerfeng294 views
Corona 初探 lua 語言,玩跨平台(iOS & android) 行動裝置開發工具 by 政斌 楊
Corona 初探 lua 語言,玩跨平台(iOS &  android) 行動裝置開發工具Corona 初探 lua 語言,玩跨平台(iOS &  android) 行動裝置開發工具
Corona 初探 lua 語言,玩跨平台(iOS & android) 行動裝置開發工具
政斌 楊924 views
Ecma script edition5-小试 by lydiafly
Ecma script edition5-小试Ecma script edition5-小试
Ecma script edition5-小试
lydiafly780 views
Golang server design pattern by 理 傅
Golang server design patternGolang server design pattern
Golang server design pattern
理 傅11K views
Ch 8 by BMG2011
Ch 8Ch 8
Ch 8
BMG2011748 views
1 C入門教學 by Sita Liu
1  C入門教學1  C入門教學
1 C入門教學
Sita Liu1.6K views
Objc under the_hood_2013 by Michael Pan
Objc under the_hood_2013Objc under the_hood_2013
Objc under the_hood_2013
Michael Pan1.7K views
C++11 smart pointers by chchwy Chang
C++11 smart pointersC++11 smart pointers
C++11 smart pointers
chchwy Chang1.6K views
Scala function-and-closures by wang hongjiang
Scala function-and-closuresScala function-and-closures
Scala function-and-closures
wang hongjiang3.3K views
iOs app 101 by Tom Sun
iOs app 101iOs app 101
iOs app 101
Tom Sun2.5K views
Ptyhon 教學 003 函數 by 信宏 陳
Ptyhon 教學 003 函數Ptyhon 教學 003 函數
Ptyhon 教學 003 函數
信宏 陳751 views

Similar to Gobject - Inherit (Chinese)

Gtk to qt by
Gtk to qtGtk to qt
Gtk to qtJen Yee Hong
2.7K views17 slides
GNOME3 延伸套件教學 by
GNOME3 延伸套件教學GNOME3 延伸套件教學
GNOME3 延伸套件教學Yuren Ju
1.3K views54 slides
Using vim by
Using vimUsing vim
Using vimRhythm Sun
577 views37 slides
大家來學GObject by
大家來學GObject大家來學GObject
大家來學GObjectShu-Yu Fu
2.4K views22 slides
版本控制 使用Git & git hub by
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub維佋 唐
6.2K views63 slides
Python 中 += 與 join比較 by
Python 中 += 與 join比較Python 中 += 與 join比較
Python 中 += 與 join比較kao kuo-tung
1.4K views25 slides

Similar to Gobject - Inherit (Chinese)(15)

GNOME3 延伸套件教學 by Yuren Ju
GNOME3 延伸套件教學GNOME3 延伸套件教學
GNOME3 延伸套件教學
Yuren Ju1.3K views
大家來學GObject by Shu-Yu Fu
大家來學GObject大家來學GObject
大家來學GObject
Shu-Yu Fu2.4K views
版本控制 使用Git & git hub by 維佋 唐
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub
維佋 唐6.2K views
Python 中 += 與 join比較 by kao kuo-tung
Python 中 += 與 join比較Python 中 += 與 join比較
Python 中 += 與 join比較
kao kuo-tung1.4K views
Git 入门实战 by icy leaf
Git 入门实战Git 入门实战
Git 入门实战
icy leaf2.6K views
大家應該都要會的工具 Git 從放棄到會用2-分支篇 by Alan Tsai
大家應該都要會的工具 Git   從放棄到會用2-分支篇大家應該都要會的工具 Git   從放棄到會用2-分支篇
大家應該都要會的工具 Git 從放棄到會用2-分支篇
Alan Tsai5K views
recover_pdb 原理與介紹 by kao kuo-tung
recover_pdb 原理與介紹recover_pdb 原理與介紹
recover_pdb 原理與介紹
kao kuo-tung831 views
Git 入門與實作 by 奕浦 郭
Git 入門與實作Git 入門與實作
Git 入門與實作
奕浦 郭1.9K views
COSCUP 2015 開源之道-Git工作坊教學簡報 by Bachue Zhou
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
Bachue Zhou656 views
Django development by loveyudu
Django developmentDjango development
Django development
loveyudu711 views
张所勇:前端开发工具推荐 by zhangsuoyong
张所勇:前端开发工具推荐张所勇:前端开发工具推荐
张所勇:前端开发工具推荐
zhangsuoyong1.8K views

Gobject - Inherit (Chinese)

  • 1. Gobject Inherit elpam.tw@gmail.com elpam@Taiwan, Taipei, 2008
  • 2. LICENSE ● 本投影片授權方式為: – 姓名標示─非商業性─相同方式分享 3.0  台灣版 – http://creativecommons.org/licenses/by­nc­sa/3.0/tw/ ● 所有的範例程式皆為 Public Domain     elpam.tw@gmail.com
  • 3. About This Slides ● All example was build by (Ubuntu 9.10) – GCC­4.3.4 – GLIB­2.22.2     elpam.tw@gmail.com
  • 4. Agenda ● GObject 's Introduction ● First Gobject Klass ● Inherit     elpam.tw@gmail.com
  • 5. GObject's Introduction     elpam.tw@gmail.com
  • 6. GTK+ (The GIMP Toolkit) ● GTK+ 最初是 GIMP 的專用開發庫,後來發展為 Unix­like 系統下開發圖形界面的應用程序的主流 開發工具之一 – 相較於 QT  ● GLib/GObject/GDK/GTK  都是為了發展 GIMP 而產生的,而 GTK+ 2.0 之後將 GLib 與 GObject 獨立出來讓其他的軟體使用 – March 11, 2002     elpam.tw@gmail.com
  • 7. GLib ● 大部份的程式語言都提供 OO 以及內建方便的演 算法 ● GLib 也提供了基本的資料結構 (Hash/Linked  Lists) ● GLib Object System 則提供了簡單的 OO  Framework for C     elpam.tw@gmail.com
  • 8. GObject ● GTK+, Pango  等函式庫裡的物件都繼承了 GOjbect 而實作 ● 提供 – 管理 Construction/ Destruction – property access method  ● 不好用 .... – message passing/ signal support     elpam.tw@gmail.com
  • 9. Before GObject ● 學習 GObject 最好的管道 – Official Documents – Trace Code/ GTK+ 裡頭的數十個範例 ●Gobject 因為沒有語法的限制,所以很容易 '' 無意 / 惡意 '' 的造成 Memory leaking ,所以: ● 依造前人留下來的方式使用。 ( 勿異想天開 ) ● 真正的了解到每一個 Macro 的用法 / 意義,並嘗試展 開之     elpam.tw@gmail.com
  • 10. GObject 4­1 First Klass Step By Step     elpam.tw@gmail.com
  • 11. 範例 ● maman­bar.{h|c} ● main.c     elpam.tw@gmail.com
  • 12. Step 1 :定義物件 ● maman­bar.h typedef struct _MamanBar MamanBar; typedef struct _MamanBarClass MamanBarClass; struct _MamanBar { 繼承 GObject  GObject parent;   /* instance members */  int a;  int b; }; struct _MamanBarClass {   GObjectClass parent;   /* class members */ };     elpam.tw@gmail.com
  • 13. 將 function 與 value 分開 ● 在 GObject 的設計裡,與 C++ 最大的概念上的 不同就是 member function 與 member value 擺放的位置 – maman_bar 放 member value – maman_bar_class 放 member function ● Why? – member value 是每一個物件都要有一份 – member function 則是每一個物件都使用同一份     elpam.tw@gmail.com
  • 14. 精確的說 ● class 裡頭放的資料是所有的物件都存取同一份 – C++ 的 static member value  – 是的, class 裡不一定要放 function point – 不是 static member function ● 而 base 裡頭放則是各個物件都保存一份     elpam.tw@gmail.com
  • 15. Step 2 :註冊 GType ● /* maman­bar.c */ 請注意:此 Function 為 Singleton ,而此函式只 GType maman_bar_get_type (void) 會 if(){} 裡只會被執行一次 {    static GType type = 0; if (type == 0) { 將自已所撰寫的 function 填寫於此 static const GTypeInfo info = {       /* You fill this structure. */       }; type = g_type_register_static (G_TYPE_OBJECT,                                    "MamanBarType",                                    &info, 0); } return type; }     elpam.tw@gmail.com
  • 16. Step 2 :註冊 GType (cont') type = g_type_register_static (G_TYPE_OBJECT,  "MamanBarType",  &info, 0); GType      g_type_register_static     (GType                         parent_type,                                                          const gchar                   *type_name,                                                          const GTypeInfo            *info,                                                          GTypeFlags                     flags); parent_type : Type from which this type will be derived. type_name : 0­terminated string used as the name of the new type. info : The GTypeInfo structure for this type. flags : Bitwise combination of GTypeFlags values. Returns : The new type identifier.     elpam.tw@gmail.com
  • 17. 什麼是 Type ( 形別 ) ● TypeInfo 裡記錄了物件的 Constructor/  Destructor/  記憶體大小及 Parent 為何 ● Glib 有實作 Type System ,管理所有的 Type – 動態的 , interpreted languages – 靜態的 , compiled languages     elpam.tw@gmail.com
  • 18. typedef struct {   /* interface types, classed types, instantiated types */   guint16 class_size;      GbaseInitFunc base_init;   GbaseFinalizeFunc base_finalize;   /* interface types, classed types, instantiated types */   GclassInitFunc class_init;   GclassFinalizeFunc class_finalize;   gconstpointer class_data;   /* instantiated types */   guint16 instance_size;   guint16 n_preallocs;   GinstanceInitFunc instance_init;    /* value handling */   const GtypeValueTable *value_table; } GTypeInfo;     elpam.tw@gmail.com
  • 19. Step 2 :註冊 GType(cont') ● 目前可以填寫的資料     static const GTypeInfo info = {       sizeof (MamanBarClass),       NULL,   /* base_init */       NULL,   /* base_finalize */       NULL,   /* class_init */       NULL,   /* class_finalize */       NULL,   /* class_data */       sizeof (MamanBar),       0,      /* n_preallocs */       NULL    /* instance_init */     };     elpam.tw@gmail.com
  • 20. Step 3 :撰寫 basic_init ● 也就是 Constructor static void maman_bar_init ( MamanBar* self ) {   self ­> a = 1;   self ­> b = 2; }     elpam.tw@gmail.com
  • 21. Register function pointer into structure     static const GTypeInfo info = {       sizeof (MamanBarClass),       NULL,   /* base_init */       NULL,   /* base_finalize */       NULL,   /* class_init */       NULL,   /* class_finalize */       NULL,   /* class_data */       sizeof (MamanBar),       0,      /* n_preallocs */       ?????    /* instance_init */     };     elpam.tw@gmail.com
  • 22. Step 4 : use it ● Add print out information in the maman_bar_init ● Please monitor the order of function launched int main (int argc, char *argv[]) {         /* this function should be executed first. Before everything  */         g_type_init(); You can find out the constructor/ type register  will be launched by this function         /* Create our object */         MamanBar *bar = g_object_new (MAMAN_TYPE_BAR, NULL);         printf(" bar­>a = (%d) bar­>b = (%d)n", bar­>a, bar­>b );         return 0; }     elpam.tw@gmail.com
  • 23. GObject 4­2 Inherit Step By Step     elpam.tw@gmail.com
  • 24. Step 1 : Define SubBar ● Please Notice This Color /* sub­bar.h */ typedef struct _MamanBar MamanBar; typedef struct _MamanBarClass MamanBarClass; struct _SubBar { 繼承 GObject  MamanBar parent;   /* instance members */  int c;  int d; };     elpam.tw@gmail.com
  • 25. Step 2 : Register SubBar's GType ● Please Notice This Color /* sub­bar.c */ GType maman_bar_get_type (void) {    static GType type = 0; if (type == 0) { static const GTypeInfo info = {                         sizeof (SubBarClass),                         NULL,   /* base_init */     NULL,   /* base_finalize */                         NULL,   /* class_init */    NULL,   /* class_finalize */                         NULL,   /* class_data */  sizeof (SubBar),                         0,          /* n_preallocs */                         sub_bar_init  /* instance_init */        }; type = g_type_register_static (MAMAN_BAR_TYPE, "SubBarType", &info, 0); }   return type;   } elpam.tw@gmail.com
  • 26. Step 3 : Try Casting ● /* main.c */ ● When we need to access parent's member  value  ((MamanBar*)subbar)­>a,   ((MamanBar*)subbar)­>b      elpam.tw@gmail.com
  • 27. Step 4 : .... ● Yes, it's very simple. No trick like previous slide  ● Please monitor the order of function launched     elpam.tw@gmail.com
  • 28. Conclusion ● The above example show the inheritance  implementation by using Gobject. ● Reader can write to child inherit sub­bar, and  monitor the timing of constructor.      elpam.tw@gmail.com
  • 29. Next ● We''ll talk about Virtual Function later     elpam.tw@gmail.com