[C++-sig] Re: problem using global variable, static variable
David Abrahams
dave at boost-consulting.com
Thu May 22 00:27:33 CEST 2003
Cyril Bonnard <cyril.bonnard at cirad.fr> writes:
> i have a problem defining global and static variables: the variable is
> not recognized
>
> this peace of code highlights the problem:
> test.h:
> class color
> {
> public:
> color() : col(0) {}
> ~color() {}
> const static color BLACK;// error
> //static color YELLOW; // same error
> //static int i; // same error
> int col;
> };
>
> test.cpp: In function `void init_module_test()':
> test.cpp:14: no matching function for call to
> boost::python::class_<color, boost::python::detail::not_specified,
> boost::python::detail::not_specified,
> boost::python::detail::not_specified>::def_readonly(const char[6],
> const color*)'
> scons: *** [test.os] Error
This should work now. Please try the latest CVS.
> i try to reproduce this "behaviour" with a global variable using pyste:
>
> class color
> {
> public:
> color() : col(0) {}
> ~color() {}
> //const static color BLACK;// error
> //static color YELLOW; // error
> //static int i; // error
> int col;
> };
>
> static color BLACK;
>
> pyste generates code which seems very strange to me:
> BOOST_PYTHON_MODULE(test)
> {
> class_< color >("color", init< >())
> .def(init< const color & >())
> .def_readwrite("col", &color::col)
> ;
>
> def("_GLOBAL__D__home_cbonnard_devlp_AMAPmod_src_GEOM_test.hef3xme",
> &_GLOBAL__D__home_cbonnard_devlp_AMAPmod_src_GEOM_test.hef3xme);
> def("_GLOBAL__I__home_cbonnard_devlp_AMAPmod_src_GEOM_test.hp8ylhc",
> &_GLOBAL__I__home_cbonnard_devlp_AMAPmod_src_GEOM_test.hp8ylhc);
This appears to be a Pyste bug. It should say:
scope().attr("BLACK") = BLACK;
> My questions are: how should i proceed to declare and use global and
> static variables? is the above pyste code known? how to resolve the
> problem?
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list