I have a structure like this:
struct Person {
std::string name;
int age;
std::string title;
float income;
};
In the python side, I have a dict like this:
person = { 'name':'Alex',
'age':36,
'title':'programmer',
'income':13435.40
}
Now I want to convert the Python dict to the C++ program by using ctypes. There is a stupid way to do this task is that we can write 4 c-style functions to set these four elements independently. How can we do this task in a single function, which can solve different data type (string, int, float)?
ctypes
can't handle C++ on its own.
SWIG can though this is equivalent to writing a C wrapper for the C++ code. It requires building native code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.