Elegantly call C++ from C -
We develop some projects in plain edit: , I should say that Separating things in a consistent There is no reason why you can not just link all your C and C ++ codes together in a binary. The interface for the C ++ code requires that you wrap the C + + API in the C API. When compiling C ++ code, by declaring a bunch of functions within You can define the duck structure in your C ++ source, and you can also get the actual C (C99). But, we have a library such as the source code (Mathematical Library) in
C ++ . We need this library so I would like to ask, what is the best way to integrate this source code? The ratio between
C and
C ++ is this
20: 1 , hence the
C + Going to + is not an option. Should we use a stable library? DLL? (It's all on Windows). Comment on the basis of discussion in
struct duck and a derivative
class.Duck is probably unnecessary. You can possibly remove the implementation in
struct duck and eliminate
class duck , thus
real (รข ?? |) |
extern "C" {...} and compiling the C client code, you can do this without an external declaration. Ex:
#ifdef __cplusplus extern "c" {#endif typedef struct duck duck; Duck * New_Dock (Int Foot); Zero delete_duck (duck * d); Zero duck_kack (duck * d, float volume); #ifdef __cplusplus} #endif
duck class from here Are:
structure ducks {}; Square duck: public duck {public: duck (int foot); ~ Duck (); Zero quake; }; Inline Duck * Actual (duck * d) {Return Static_cast & lt; Duck * & gt; (D); } Duck * new_dig (int fee) {new duck (foot) returned; } Zero delete_duck (duck * d) {actual delete (d); } Zero duck_kack (duck * d, float volume) {physical (d) - & gt; Quack (quantity); }
Comments
Post a Comment