[C++-sig] Using .add_property with make_getter.

Kirsebom Nikolai nikolai.kirsebom at siemens.no
Tue Jun 24 11:53:17 CEST 2003


I have the following c++ class:
class PyDLEPRInterface : public DLEPRInterface
{
public:
	PyDLEPRInterface();
	PyDLEPRInterface(const PyDLEPRInterface& objectSrc);
};

PyDLEPRInterface::PyDLEPRInterface(const PyDLEPRInterface& objectSrc)
{
}

PyDLEPRInterface::PyDLEPRInterface()
{
}

The class DLEPRInterface defines some public attributes, example
	CString m_DocumentCategory;
	int m_UserID;


I have a converter for converting CString <--> python string.
See code in thread "Exception second time loaded" 20th of June.

The two attributes are exposed with the statements:
	.def_readonly("UserID", &PyDLEPRInterface::m_UserID)
and
	.add_property("DocumentCategory",
make_getter(&PyDLEPRInterface::m_DocumentCategory,
return_value_policy<return_by_value>()))

When running in Python, the UserID is available however reading the
DocumentCategory attribute produces the following traceback:

import DocuLive  #<<Module exposing function to get an existing
PyDELEPRInterface object
import CString #<<Module handling the conversion
v = DocuLive.getit() #<<Fetch the exisiting object
v.UserID #<<Print the value for UserID attribute
44
v.DocumentCategory 
Traceback (most recent call last):
  File "<input>", line 1, in ?
TypeError: bad argument type for built-in operation


I'm running the python statements in a PyCrust (wxPython/wxWindows) shell
application.
In my posting 20th of June I asked for help relating to exception when
staring the second time.  It appears that the starting of the mainloop in
the PyCrust application produces the exception if other applications (in
Windows) has been activated in between.  Have not found the reason for this
behaviour.
	
All help is appreciated.
Nikolai Kirsebom




More information about the Cplusplus-sig mailing list