[C++-sig] problem using global variable, static variable

Cyril Bonnard cyril.bonnard at cirad.fr
Tue May 20 10:53:55 CEST 2003


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


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);

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?










More information about the Cplusplus-sig mailing list