boostorg / boostorg/python

Exposing inherited static member variables as static property with the same name leads to exception

Ouverte
#192 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
C++
Étoiles
537
Forks
223
Merge moyen
11 h 22 min
PR mergées (30 j)
2

Description

This bug has been reported by Luke Titley in 2009 on boost-build mailing list. It is still reproducible with the version of boost python 1.65 on Visual C++ 2017. I'm using the Luke's code snippet to show the problem.

There are two boost python classes, one inheriting from the other; each with a static member variable of the same name.

//---------------------------------------------------------------------------------------
// C++ Classes
//---------------------------------------------------------------------------------------
class Base
{
public:

static const wstring Name;

};
const wstring Base::Name(L"Base");

//---------------------------------------------------------------------------------------
class Derived : public Base
{
public:

static const wstring Name;

};
const wstring Derived ::Name(L"Derived");

//---------------------------------------------------------------------------------------
// Boost Python Bindings
//---------------------------------------------------------------------------------------
wstring getBaseName()
{
return Base::Name;
}
void exposeBase()
{
py::class_("Base")
.add_static_property("Name", &getBaseName) ;
}

//---------------------------------------------------------------------------------------
wstring getDerivedName()
{
return Derived::Name;
}
void exposeDerived()
{
py::class_ >("Derived")
.add_static_property("Name", &getDerivedName) ;
}

//---------------------------------------------------------------------------------------
BOOST_PYTHON_MODULE(nmx)
{

exposeBase();
exposeDerived();
}

The import of the module fails and it's caused by throwing exception in exposedDerived (add_static_property).

Best Regards,
Gabriel

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.