[C++-sig] Re: C++ Operators and Constructers

Stefan Wolf wolfs at in.tum.de
Wed May 12 01:39:04 CEST 2004

Okay, the following is compiling. How do I get it into python, so that I can use the + operator with two symbol objects (which works in C++)?

#include <boost/python.hpp>
#include <iostream>

using namespace boost::python;

namespace GiNaC {
	class ex;
	class basic;
	class symbol;

	class basic {
			basic(class basic & other);
			basic(int value);
			friend const class ex operator+(class ex& lh);
			int value;

	basic::basic() { }
	basic::basic(int value):value(value) {

	class symbol : public basic {
			symbol(const std::string& name, int value);
			friend const class ex operator+(class ex& lh);
			std::string name;

	symbol::symbol(const std::string& name, int value) : 
		basic(value), name(name) 

	class ex {
			ex(const basic& other);
			const class basic * bp;

	ex::ex(const basic& other) : bp(&other) {

	const ex operator+(const ex &lh, const ex& rh){
		return (ex(basic(lh.bp->value + rh.bp->value)));

  Stefan Wolf <glowwormy at web.de>
  wolfs at in.tum.de, wolfs at fs.tum.de,
  stefan.wolf at mytum.de,
  Stefan.Wolf at stud.tu-muenchen.de

"Tú puedes quedarte, pero yo me voy" (mente de Homer Simpson)

()  ascii ribbon campaign - against html mail 
/\                        - against microsoft attachments
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20040512/b1c5ede4/attachment.pgp>

More information about the Cplusplus-sig mailing list