[C++-sig] default arguments

chuzo okuda okuda1 at llnl.gov
Thu May 23 00:38:46 CEST 2002


I cannot remember about reading any emails about default arguments, but
it seems that it does not work at present.

--- code ---
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
using namespace boost::python;
#include <iostream>

/************************************************************/
/*                                                          */
/*             test of default arguments                    */
/*                                                          */
/************************************************************/

std::string testString(std::string s="Hello World") {return s;}
int testInteger(int i1, int i2, int i3=3, int i4=4, int i5=5) {
   return i1 + i2 + i3 + i4 + i5;
}

BOOST_PYTHON_MODULE_INIT(defaultArgTest)
{
   module("defaultArgTest")
      .def("testString", &testString)
      .def("testInteger", &testInteger)
      ;
}
-------

testString() should print "Hello World" and testInteger(0,0) should
print 12 like in C++ code, but instead I got TypeError message...


gps01(374) python
Adding parser accelerators ...
Done.
Python 2.2 (#1, Jan 22 2002, 14:39:03) [C] on osf1V5
Type "help", "copyright", "credits" or "license" for more information.
>>> from defaultArgTest import *
>>> testString("hi")
'hi'
>>> testString()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: bad argument type for built-in operation
>>> testInteger(0,0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: bad argument type for built-in operation
>>> testInteger(0,0,1,1,1)
3
>>>





More information about the Cplusplus-sig mailing list