[C++-sig] Returning NULL

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Dec 19 02:29:14 CET 2003


Your question is not clear at all, but I'll try an answer anyway (untested):

boost::python::object
foo(int i)
{
  if (i == 0) return boost::python::object(AnInstance);
  return boost::python::object(); // None in Python
}

You cannot return NULL to Python, only None.
For this to work you need a class_<SomeObject> somewhere else.

Ralf

--- Ammar Hakim <ahakim777 at yahoo.com> wrote:
> Hello,
> 
> How do I wrap a function which can return either an
> object or NULL? For example:
> 
> SomeObject
> foo(int i)
> {
>    if(i == 0)
>      return AnInstance;
>    else 
>      return NULL;
> }
> 
> Cheers,
> Ammar
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Protect your identity with Yahoo! Mail AddressGuard
> http://antispam.yahoo.com/whatsnewfree
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/




More information about the Cplusplus-sig mailing list