Hello, On Tue, Mar 29, 2011 at 12:23:46PM +0200, Nisoli Isaia wrote:
even with your suggested correction, it gives exactly the same error. I think the problem lies in some way in my assignment operator, when I use the overloaded operator= of numeric.
I don't think there's anything wrong about the assignment operator. As a matter of fact the following program works for me just fine: #include <ginac/ginac.h> #include <iostream> using namespace std; using namespace GiNaC; class rinterval { public: numeric min; numeric max; numeric error; rinterval(const numeric&, const numeric&, const numeric&); //Friend friend const rinterval dynamic(const rinterval&); friend std::ostream &operator<< (std::ostream& os, const rinterval& inter) { return os << "[" << inter.min << "," << inter.max <<"], error = " << inter.error << endl; } rinterval& operator=(const rinterval& rhs); }; rinterval::rinterval(const numeric& input1, const numeric& input2, const numeric& miserr) { if (input1 > input2) { min = input2; max = input1; } else { min = input1; max = input2; } error = miserr; } const rinterval dynamic(const rinterval& domain) { numeric a = "1.47777777777777777777777777779999"; rinterval temp(a*domain.min, a*domain.max, domain.error); cout << temp; return temp; } rinterval& rinterval::operator=(const rinterval &rhs) { if (this == &rhs) return *this; this->min = rhs.min; this->max = rhs.max; error = rhs.error; return *this; } int main (void) { numeric a(1, 10); numeric b(2, 10); rinterval inter(a, b, numeric(0.00001)); inter = dynamic(inter); cout << inter << endl; } The output is [0.14777777777777777779,0.29555555555555555557], error = 1.0000000000000000818E-5 [0.14777777777777777779,0.29555555555555555557], error = 1.0000000000000000818E-5 I use latest GiNaC and CLN from git. Compiler: g++ --version g++ (Debian 4.4.5-8) 4.4.5 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. OS: uname -rms Linux 2.6.38.2-ck1 x86_64 Best regards, Alexei