[C++-sig] Constructor w/ string

Scott A. Smith ssmith at magnet.fsu.edu
Tue Jun 11 23:51:43 CEST 2002


Greetings,

A simple problem I'll bet. I have three constructors in my
(now very simple) class. One that takes no arguments, one that
does self-construction, and one that takes a string. When I
export these in Boost 1.25.0 all three work fine, but with 1.28.0
only the first two work , the third always dies with complaints about
a Debug Assertion Failure in dgbheap.c from the Python IDE.

I hope someone can help me figure out the following:

1.) How to I change the export function to make this work again?
2.) Is there documentation that has this in detail?

I often look through http://mail.python.org/pipermail/c++-sig/ and have
used the new Google search on the main WWW page, but haven't found anything.
The getting_started2 example works OK and it also has a construtor that
uses a string, but upon exiting the interpreter it gives the same error
message when I add in empty & self constructors. (I am unclear on why that
example needs <iostream> and why exactly the const string& must be just
string
in the corresponding init function, however neither of these influences my
result.)

I am using Python 2.2.1 & MSVC++ 6.0.  My class header, code, and the
Boost.Python interface are below if that helps.  Note that in my non-clipped
verson I do actually use the string I construct with, same problem though.

Thanks for any help.
Scott

/* Isotope.h ************************************************************/
# include <string>
class Isotope
{
int Iso;					// An isotope index

public:

Isotope();
Isotope(const Isotope& I);
Isotope(const std::string& symbol);
};

/* Isotope.cc ***********************************************************/

#include "Isotope.h"		// Include the interface
#include <string>			// Include libstd++ string class

Isotope::Isotope()                          { Iso = 0; }
Isotope::Isotope(const Isotope& I)          { Iso = I.Iso;}
Isotope::Isotope(const std::string& symbol) { Iso = 0; }

/* PythonInterface.h ****************************************************/

#include "Isotope.h"
#include <boost/python/class_builder.hpp>
#include <boost/python/reference.hpp>
namespace python = boost::python;

BOOST_PYTHON_MODULE_INIT(gamma)
  {
    python::module_builder gamma("gamma");
    python::class_builder<Isotope> Isotope_class(gamma, "Isotope");
    Isotope_class.def(python::constructor<>());
    Isotope_class.def(python::constructor<Isotope>());
    Isotope_class.def(python::constructor<std::string>());
  }



-----------------------------------------
-----------------------------------------

 Dr. Scott A. Smith
 Associate in Research
 National High Magnetic Field Laboratory
 1800 East Paul Dirac Drive
 Tallahassee, FL 32310

 phone: (850) 644-6348
 FAX:   (850) 644-1366
 email: ssmith at magnet.fsu.edu
 http://www.magnet.fsu.edu
 http://gamma.magnet.fsu.edu






More information about the Cplusplus-sig mailing list