Using boost python I need create nested namespace.
Assume I have following cpp class structure:
namespace a
{
class A{...}
namespace b
{
class B{...}
}
}
Obvious solution not work:
BOOST_PYTHON_MODULE( a ) {
boost::python::class_<a::A>("A")
...
;
BOOST_PYTHON_MODULE(b){
boost::python::class_<a::b::B>("B")
...
;
}
}
It causes compile-time error: linkage specification must be at global scope
Is there any way to declare class B that would be accessed from Python as a.b.B?
What you want is a boost::python::scope.
Python has no concept of ‘namespaces’, but you can use a class very much like a namespace:
Then in python, you have:
All
a,a.A,a.banda.b.Bare actually classes, but you can treataanda.bjust like namespaces – and never actually instantiate them