First, your sample should really get the correct virtual dtor.
Then add only one free function with a C binding for each function that is part of the interface, simply by delegating:
"sample.h"
#ifdef __cplusplus extern "C" { #endif typedef struct sample sample; sample* sample_create(); sample* sample_create0(); sample* sample_create1(); void sample_destroy(sample*); int sample_get(sample*); void sample_set(sample*, int); #ifdef __cplusplus } #endif
Sample-c.cpp
#include "sample.h"
"sample.hpp"
// Your C++ header here, with class definition
"sample.cpp"
#include "sample.hpp"
source share