A thing I do not understand
- From: Friedrich <frido q-software-solutions de>
- To: gtk-list gnome org
- Subject: A thing I do not understand
- Date: Tue, 07 Oct 2008 18:24:57 +0200
If I write class which derives frm another and add this to the
class_init method
static void qtestderived_class_init(gpointer g_class,
gpointer g_class_data){
QTestDerivedClass *selfClass = QTESTDERIVED_CLASS(g_class);
superClass = g_type_class_peek_parent(selfClass);
g_type_class_add_private(selfClass, sizeof(struct QTestDerivedData));
/* assign virtual methods */
selfClass->get_someIntVal = &qtestderived_getIntValImpl;
selfClass->set_someIntVal = &qtestderived_setIntValImpl;
}
I can later access superClass to call the parents method e.g like
this:
static int qtestderived_getIntValImpl(QTestDerived *self) {
int result = superClass->get_someIntVal(QTEST(self));
return result;
}
However if I put all the handling for getting a superClass pointer in
this method like this:
static int qtestderived_getIntValImpl(QTestDerived *self) {
QTestDerivedClass *selfClass = QTESTDERIVED_CLASS(self);
QTestClass *sClass = g_type_class_peek_parent(selfClass);
int result = sClass->get_someIntVal(QTEST(self));
return result;
}
Then the following happens, the stuff runs fine up to theline
QTESTDERVIVED_CLASS, but while calling g_type_clas...
I got back a NULL pointer. I simple do not understand why that
happens. The example in the docs looks like this:
The function g_type_class_peek_parent is used to access the original parent class structure. Its input is a pointer to the class of the derived object and it returns a pointer to the original parent class structure. The code below shows how you could use it:
static void
b_method_to_call (B *obj, int a)
{
BClass *klass;
AClass *parent_class;
klass = B_GET_CLASS (obj);
parent_class = g_type_class_peek_parent (klass);
/* do stuff before chain up */
parent_class->method_to_call (obj, a);
/* do stuff after chain up */
}
So it looks very similiar...
I've no idea where my thoughts go wrong.
Could anyone tell me about this?
Thanks in advance
Friedrich
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]