[C++-sig] Instantiating class_<> objects without use of aninterpreter? - Bayesian Filter detected spam
Podpruzhnikov Yuri
ypodpruzhnikov at mcode.ru
Wed Feb 21 12:50:20 CET 2007
My decision of this problem is (it may be is not best):
1)Declare all class_<> only in module definition
(BOOST_PYTHON_MODULE(DataTypes){...}):
BOOST_PYTHON_MODULE(DataTypes)
{
class_<OneDataType>("OneDataType", init<int>())
.def("someFunc", &OneDataType::someFunc);
class_<SomeFactoryClass, boost::noncopyable>("SomeFactoryClass",
no_init);
class_<OneFactory, bases<SomeFactoryClass> >("OneFactory")
.def("makeSomething",
&OneFactory::makeSomething);
}
2) Write this in all factories next code:
object OneFactory::makeSomething()
{
return object(OneDataType(42));
}
ATTENTION:
Definition of class_<OneDataType> always must be before create
object(OneDataType(42))
If class_<OneDataType> and function, which create
object(OneDataType(42)), declared in one module - all right
But its declared in different modules -
module contain class_<OneDataType> must be imported before
module contain function, which create object(OneDataType(42))
More information about the Cplusplus-sig
mailing list