[comp.std.c++] Pointer arguments for overloaded operators

teague@laic.rdd.lmsc.lockheed.com (Alan Teague) (03/27/91)

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