Reputation: 249
I have a C++ class with its header CFileMapping.cpp and CFileMapping.h I want to call the c++ function CFileMapping::getInstance().writeMemory( )
in my C code.
Even when I wrapped my C++ code and added
#ifdef __cplusplus
extern "C"
in the header file to deal with the c++ code and added
extern "C"
in the cpp file, I still can't call my function like this
CFileMapping::getInstance().writeMemory().
Could any one help me? I want to keep my c++ code and be able to call it when I want.
Upvotes: 2
Views: 199
Reputation: 6556
You should create C wrapper for your C++ call:
extern "C"
{
void WriteMemFile()
{
CFileMapping::getInstance().writeMemory( );
}
}
// The C interface
void WriteMemFile();
IMPORTANT: The extern "C"
specifies that the function uses the C naming conventions.
Upvotes: 4