noddy example, writing C modules for python

Bernd Nawothnig Bernd.Nawothnig at t-online.de
Wed Jun 2 08:37:36 EDT 2004


Hi Torsten,

On Sun, 30 May 2004, Torsten Mohr <tmohr at s.netic.de> wrote:

> based on the example module "noddy" i wrote an own one
> and i have problems accessing the elements in the python
> objects.  I defined the example object:

> typedef struct {
>   PyObject_HEAD
>   int num;
> } pmod_obj;


> static PyMemberDef pmod_members[] = {
>   {"number", T_INT, offsetof(pmod_obj, num), 0, /* LINE 143 */
>   "pmod number"},
>   {NULL}
> };


> When i compile this under Win32, i get this (in german):
> pmod.cc(143) : error C2552: 'pmod_members': Initialisierung nicht
> zusammengesetzter Typen mit Initialisierungsliste ist nicht möglich
>         'PyMemberDef' : Typen mit benutzerdefinierten Konstruktoren sind
> nicht  'aggregate'

The explanation is shown quite clear in plain German - where is your
problem? :-) One is sure: your problem has nothing to do with Python
but with C++. Only for short, look at this example:

#v+
class A {
  public:
  char *s;
  A(): s("") {}
} a = {"Hallo"};
#v-

That cannot compile too because there are two different
initializations: one via constructor and the second via initialization
list. So, of course, Gnu g++ also complains:

test.cc:24: error: `a' must be initialized by constructor, not by `{...}'



HTH & f'up2

Bernd

-- 
Those who desire to give up freedom in order to gain security,
will not have, nor do they deserve, either one. [T. Jefferson]



More information about the Python-list mailing list