struct and function-pointer casting
- From: Maurice <mauricex@xxxxxxx>
- Date: Fri, 29 Apr 2005 14:43:59 +0200
Hi,
Is it legal to cast from void(*)(A*) to void(*)(B*)?
Is it legal to cast from struct Derived{Base b; ...} to struct Base?
I'm trying to get some inheritance and polymorphism in C
and I end up with the following code:
struct Base {
void(*func)(struct Base*);
};
struct Derived {
struct Base base;
/* ... */
};
void derived_func(struct Derived* d) {}
int main() {
struct Derived d = {{derived_func} /*...*/ };
struct Base* b = &d;
b->func(b);
}
Thank you.
.
- Follow-Ups:
- Re: struct and function-pointer casting
- From: Eric Sosman
- Re: struct and function-pointer casting
- Prev by Date: Re: what do c developers do without the stl?
- Next by Date: Re: Caaling assembly routine in c
- Previous by thread: two dimensional arrays:
- Next by thread: Re: struct and function-pointer casting
- Index(es):