[GiNaC-devel] Subclassing symbol
Jan Rheinländer
jrheinlaender at gmx.de
Wed May 11 21:10:29 CEST 2016
Hi,
something must be wrong with my subclass, but I don't understand it. I
subclassed symbol to get a non-commutative version:
---------- HEADER --------------
#include <ginac/symbol.h>
namespace GiNaC {
class ncsymbol: public symbol {
public:
ncsymbol(const symbol& s);
explicit ncsymbol(const std::string & initname);
ncsymbol(const std::string & initname, const std::string & texname);
unsigned return_type() const { return
return_types::noncommutative_composite; }
};
GINAC_DECLARE_UNARCHIVER(ncsymbol);
}
---------- IMPLEMENTATION -------------
#include <ginac/ginac.h>
namespace GiNaC {
// non-commutative symbol
ncsymbol::ncsymbol() : symbol() { }
ncsymbol::ncsymbol(const symbol& s) : symbol(s) { }
ncsymbol::ncsymbol(const std::string & initname) : symbol(initname) { }
ncsymbol::ncsymbol(const std::string & initname, const std::string &
texname) : symbol(initname, texname) { }
GINAC_BIND_UNARCHIVER(ncsymbol);
--------------------------------------
But when I execute the following code the program crashes when printing x:
symbol x("x");
x = ncsymbol("y");
std::cout << x << std::endl;
It does not crash if I print ncsymbol("y") directly (without assigning
it to x first). Can anybody explain why? Did I forget to implement an
essential method?
Thanks!
Jan
More information about the GiNaC-devel
mailing list