wrapping c plus plus classes in Python

This is a quick and dirty way to interface C++ code with Python, translating one or more C++ classes in Python objects. First, we need some c++ sample code: //myclass.h #ifndef MYCLASS_H #define MYCLASS_H #include <string> using namespace std; namespace pets { class Dog { public: Dog(string name, int age); virtual ~Dog(); string talk(); protected: string m_name; int m_age; }; } //myclass.cpp #include "myclass.h" #include <string> namespace pets { Dog::Dog(std::string name, int age): m_name(name),m_age(age) { } Dog::~Dog() { } std::string Dog::talk() { return "BARK! I am a DOG and my name is "+m_name; } } now, we can try a little test program just to exercise our class: ...

August 8, 2016 · Andrea Manzini