Re: Base class and OOP in C
From: Måns Rullgård (mru_at_inprovide.com)
Date: 03/29/05
- Next message: Paul Pluzhnikov: "Re: Base class and OOP in C"
- Previous message: shakahshakah_at_gmail.com: "Re: Using make"
- In reply to: j_mckitrick_at_bigfoot.com: "Base class and OOP in C"
- Next in thread: Paul Pluzhnikov: "Re: Base class and OOP in C"
- Reply: Paul Pluzhnikov: "Re: Base class and OOP in C"
- Reply: jonathon: "Re: Base class and OOP in C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Mar 2005 17:19:52 +0200
j_mckitrick@bigfoot.com writes:
> Hi all,
>
> I am trying to implement some C++ functionality in C.
>
> Suppose I have several libraries that share behavior and properties,
> such as version, working directory, and so on. I want other
> libraries to extend this behavior without having to duplicate any
> code. For instance:
>
> typedef struct base
> {
> char version[32];
> char path[32];
> } base_t;
>
> typedef struct foo
> {
> base_t *base;
> int data;
> } foo_t;
>
> typedef struct bar
> {
> base_t *base;
> int data;
> } bar_t;
>
> I want the derived modules to link with the base library, so that my
> application can link with only the derived modules and still be able
> to call the base functions without having to link to that library or
> call 'wrapper' functions in the derived modules.
>
> Is there a way to do this?
If you change your declarations slightly, it will work:
typedef struct base {
whatever;
} base_t;
typedef struct foo {
base_t base; /* not a pointer */
foo_additions;
} foo_t;
typedef struct bar {
base_t base;
bar_additions;
} bar_t;
Now, a pointer to any of these, will be valid as a base_t *.
-- Måns Rullgård mru@inprovide.com
- Next message: Paul Pluzhnikov: "Re: Base class and OOP in C"
- Previous message: shakahshakah_at_gmail.com: "Re: Using make"
- In reply to: j_mckitrick_at_bigfoot.com: "Base class and OOP in C"
- Next in thread: Paul Pluzhnikov: "Re: Base class and OOP in C"
- Reply: Paul Pluzhnikov: "Re: Base class and OOP in C"
- Reply: jonathon: "Re: Base class and OOP in C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|