How to handle protected destructor?

Asked by John Pursey

I have a class like this:

class IFoo
{
public:
    virtual void DoSomething() = 0;
protected:
    virtual ~IFoo() {}
};

When I wrap this class, the generated code fails because IFoo's destructor is not accessible. I didn't see any parameters on the Module.add_class method or on CppClass which allows setting a destructor protection level. How can I work around this?

Question information

Language:
English Edit question
Status:
Solved
For:
PyBindGen Edit question
Assignee:
No assignee Edit question
Solved by:
Gustavo Carneiro
Solved:
Last query:
Last reply:
Revision history for this message
Gustavo Carneiro (gjc) said :
#1

There are only two options to instruct pybindgen not to call the destructor:

   - Pass the option is_singleton=True, to tell pybindgen it is a singleton class;

   - Enable reference counting on the class, tell pybindgen about the reference counting memory policy.

Unfortunately is_singleton=True has other side effects (disables support for virtual methods). I guess you could consider this a bug in PyBindGen.

Revision history for this message
Best Gustavo Carneiro (gjc) said :
#2
Revision history for this message
John Pursey (jpursey) said :
#3

Thanks Gustavo Carneiro, that solved my question.

Revision history for this message
John Pursey (jpursey) said :
#4

I actually have all three cases in the code I am wrapping: a singleton, ref-counted bases classes, and some classes which just have protected destructors. Thanks for the help and quick fix!

John