So, I read Developing a wrapper API for object-oriented C ++ code , and I like the approach I used in my library - opaque handles for each corresponding C ++ class; avoiding usevoid*
But now I came across the thought of “interfaces” and base classes. For example, I have a class hierarchy of “channel” classes — a base class for a “channel” and derived concrete classes for, for example, serial communications, buffers in memory, sockets, etc.
So, I have a:
typedef struct serial_channel serial_channel;
typedef struct socket_channel socket_channel;
typedef struct memory_channel memory_channel;
serial_channel* create_serial_channel();
socket_channel* create_socket_channel();
memory_channel* create_memory_channel();
But I want to be able to pass any of them to a function in order to associate it with the 'device' object:
void associate_device_with_channel(device*, channel*);
++, . C - channel C?
, , , void * ?
typedef void* channel;
void associate_device_with_channel(device*, channel*);
, ?
, , :
void associate_device_with_serial_channel(device*, serial_channel*);
void associate_device_with_socket_channel(device*, socket_channel*);
void associate_device_with_memory_channel(device*, memory_channel*);
, , .
- , ? - , void *?