KEISTER@CARNOT.PHYS.CMU.EDU (01/12/90)
I am running g++ on a VMS VAX, and am having trouble making a unary minus operator for a complex 2x2 matrix. I have set up my own complex class (Cmplx) with its own unary minus, which compiles and runs correctly, but g++ doesn't like my treatment of unary minus on the matrix. The error message and the relevant sections of code follow. This all works correctly under cfront on a DECstation, and I don't have g++ installed on any other machine to know if this is VMS-specific. Brad Keister Physics Department Carnegie Mellon U unary.cc: In function class Pauli operator - (const class Pauli &): unary.cc:63: wrong type argument to unary minus unary.cc:63: wrong type argument to unary minus unary.cc:63: wrong type argument to unary minus unary.cc:63: wrong type argument to unary minus // self-contained test file... class Cmplx { double re, im; public: Cmplx(double r = 0.0, double i = 0.0) {re = r; im = i;} // ctor Cmplx(const Cmplx& z) {re = z.re; im = z.im;} // copy initializer ~Cmplx() {} // dtor (automatic) // ... Cmplx operator-() // unary - { return Cmplx(-re, -im); } }; class Pauli { Cmplx s11, s12, s21, s22; public: Pauli(double a = 0); // ctor (accomodates no-arg case) Pauli(const Cmplx& ss11, const Cmplx& ss12, const Cmplx& ss21, const Cmplx& ss22); // specify individual components (no defaults) Pauli(const Pauli& a); // copy initializer ~Pauli() {} // dtor (automatic) Pauli& operator=(const Pauli& a); // assignment // ... friend Pauli operator-(const Pauli& a); // unary - }; Pauli::Pauli(double a) // ctor (accomodates no-arg case) { s11 = a; s22 = a; s12 = 0; s21 = 0; } Pauli::Pauli(const Cmplx& ss11, const Cmplx& ss12, const Cmplx& ss21, const Cmplx& ss22) // specify individual components (no defaults) { s11 = ss11; s12 = ss12; s21 = ss21; s22 = ss22; } Pauli::Pauli(const Pauli& a) // copy initializer { s11 = a.s11; s12 = a.s12; s21 = a.s21; s22 = a.s22; } Pauli& Pauli::operator=(const Pauli& a) // assignment { s11 = a.s11; s12 = a.s12; s21 = a.s21; s22 = a.s22; return *this; } // ... Pauli operator-(const Pauli& a) // unary - { return Pauli(-a.s11, -a.s12, -a.s21, -a.s22); }