The method is to make external functions with using handles. Handles will be pointers to classes which you will put as an explicitly C++ pointer this. The difference is what in C++ that pointer is hidden. See C++ implementation, like I do it in VisualC++. In GCC should be some similar. You will compille it in C++. In C programs use the .h file and the resulted object file as implementation, not the .cpp. Declarations between
[color blue]#ifdef __cplusplus[/color] and [color blue]#endif[/color] will not be visible from C programs.
The limitation is what you will not be able to overwrite xwrite(void*) function. In my opinion it became a FAQ.
[color blue]
[color green]//classdecl.h[/color]
#if !defined(__CLASSDECL_H)
#define __CLASSDECL_H
#ifdef __cplusplus
class xxx
{
int write();
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int xwrite(void* handle);
#ifdef __cplusplus
}
#endif
#endif
[color green]//end of classdecl.h
//classdecl.cpp[/color]
#include"classdecl.h"
int xxx::write()
{
return 0;
}
int xwrite(void* handle)
{
return ((xxx*)handle)->write();
}
[color green]//end of classdecl.cpp[/color]
[/color]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.