🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #2166

problems with unary minus

#2166
From: KEISTER
Date: Fri, 12 Jan 1990 14:17
89 lines
2656 bytes
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);
}
Technical Details
Message-ID: <9001121539.AA00596@life.ai.mit.edu>
Path: arc1-ca.pugleaf.net!utzoo!telly!philmtl!uunet!tut.cis.ohio-state.edu!CARNOT.PHYS.CMU.EDU!KEISTER

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!philmtl!uunet!tut.cis.ohio-state.edu!CARNOT.PHYS.CMU.EDU!KEISTER
From: KEISTER@CARNOT.PHYS.CMU.EDU
Newsgroups: gnu.g++.bug
Subject: problems with unary minus
Message-ID: <9001121539.AA00596@life.ai.mit.edu>
Date: 12 Jan 90 14:17:00 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 89