🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #984

Pointer arguments for overloaded operators

#984
From: Alan Teague
Date: Tue, 26 Mar 1991 18:27
34 lines
1561 bytes
This is what I want to do:

class alpha {
  ...
  // These are allowed and work with both g++ and ccxx:
  friend alpha *operator+( alpha&, alpha& );
  alpha *operator+( alpha& );

  // This is what I really want to do:
  friend alpha *operator+( alpha*, alpha* );  // Desired operation
	// Not allowed by ARM:  pg 330
	//  "An operator function must either be a member function or take
	//   at least one argument of a class or a reference to a class"

  // The function I do not want to use, if possible, is:
  alpha *alpha_append( alpha*, alpha* );  // Which works exactly the way I want.

  // So I tried this:
  alpha *operator+( alpha* );  // Compiles with no warnings or messages
   // But when used, the use generates an error message:
   //   alpha *a = new alpha();
   //   alpha *b = new alpha();
   //   alpha *c = a + b;   -- Error message about pointers

  ...
};

It seems to be perfectly reasonable to want to have the operator work on
pointers to class instances.  Have I missed some subtle point which is not 
discussed in the ARM commentary (or I haven't found yet)?


-- Alan Teague
   teague@stc.lockheed.com
Technical Details
Message-ID: <979@laic.rdd.lmsc.lockheed.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!voder!pyramid!leadsv!laic!teague

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!voder!pyramid!leadsv!laic!teague
From: teague@laic.rdd.lmsc.lockheed.com (Alan Teague)
Newsgroups: comp.std.c++
Subject: Pointer arguments for overloaded operators
Keywords: operators
Message-ID: <979@laic.rdd.lmsc.lockheed.com>
Date: 26 Mar 91 18:27:25 GMT
Organization: Lockheed AI Center, Palo Alto, CA
Lines: 34