This could be something simple I'm missing but I can't find any explanation.
Given an abstract class, which is implemented elsewhere and its interface provided by an exported function:
class IFoo {
public:
virtual ~IFoo(){}
virtual void bar()=0;
};
extern IFoo* get_interface();
In c++ I would use this as:
IFoo* foo = get_interface();
foo->bar();
If I SWIG this, I can import the module and assign get_interface() to a variable:
import myfoo
foo = myfoo.get_interface()
But I can't access foo.bar():
>>> foo.bar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'SwigPyObject' object has no attribute 'bar'
What am I missing?
Thanks!
Here is the full thing if the fragments above aren't clear enough:
The *.i file:
%module myfoo
#define SWIG_FILE_WITH_INIT
%include "myfoo.h"
%{
#include "myfoo.h"
%}
The myfoo.h header:
class IFoo {
public:
virtual ~IFoo(){}
virtual void bar()=0;
virtual void release()=0;
};
extern IFoo* get_interface();
The implementation file (myfoo.cpp)
#include "myfoo.h"
#include <iostream>
class Foo : public IFoo {
public:
Foo(){}
~Foo(){}
void bar();
void release();
};
void Foo::bar() {
cout << "Foo::bar()..." << endl;
}
void Foo::release() {
delete this:
}
IFoo* get_interface() {
return new Foo();
}
%feature("director") IFoo, but I think you're missing something additional too. Can you include all of a complete minimal example rather than just selected fragments?