Path: utzoo!mnetor!uunet!husc6!uwvax!oddjob!nucsrl!morrison From: morrison@eecs.nwu.edu (Vance Morrison) Newsgroups: comp.lang.c++ Subject: Re: Why doesn't c++ allow overloading member operators? Message-ID: <8180005@eecs.nwu.edu> Date: 17 Mar 88 19:24:59 GMT References: <11778@sri-spam.istc.sri.com> Organization: Northwestern U, Evanston IL, USA Lines: 30 The question is "why doen't c++ allow you to overload the "." operator. I asked myself this very question and I don't have a good reason, but I did realise that the "." operator is fundamentally different from most other operators. Namely its right operand MUST BE A COMPILE TIME CONSTANT DEFINED FOR THAT PARTICULAR CLASS/STRUCTURE. I don't believe that this is the case with any other operator. In order for c++ to alow "mimicking" of this operator's semantics, (which is what all good overloaded operations do) there has to be a facility in c++ to access this compile time info. This opens up a whole new set of problems which are better thought out carefully first. The real reason you probably want overloading is to allow "controled access" to instance variables. What would meet this need without overloading the "." is for c++ to REDEFINE the "." operator for the class EXAMPLE so example.member means example.member() and if example.member() does not exist, then the "." means what it used to. I know for a fact that AT&T c++ does NOT allow member fuctions and member variables to have the same name so this would not break any code. SO HOW ABOUT IT?? Vance Morrison morrison@accuax.nmu.edu