Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!tut.cis.ohio-state.edu!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: overloading operators on pointers to a class Message-ID: <9340@alice.UUCP> Date: 10 May 89 19:14:09 GMT References: <8905091935.AA26577@AENEAS.MIT.EDU> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 24 In article <8905091935.AA26577@AENEAS.MIT.EDU>, FISK@BOWDOIN.BITNET writes: > I would like to overload an operator that is defined on pointers > to a class. Here is what I would like to do. Is this possible? > struct M { ... }; > typedef struct M* P; > P a,b,c; > a = b+c // the "+" should be something like P::operator+(P,P) No. An overloaded operator must have at least one operand that is a class (not just a pointer to a class). This is to prevent you from changing the meaning of built-in operators. If you really want to do something like that, you can (in C++ 2.0): define a class called, say Mptr and define Mptr::operator->(). Then you can use an Mptr pretty much as if it were a pointer, but you can overload functions based on it, give it a constructor and destructor, and so on. -- --Andrew Koenig ark@europa.att.com