Fix a bug in external class function definitions and allow specifying functions that take smart pointers for 'this'