Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!orion.oac.uci.edu!eapu034 From: eapu034@orion.oac.uci.edu (Carl F. Edman) Newsgroups: comp.std.c++ Subject: Re: foo() => foo Keywords: function call syntax Message-ID: <26B91560.11044@orion.oac.uci.edu> Date: 3 Aug 90 06:10:40 GMT References: <26717@pasteur.Berkeley.EDU> Reply-To: eapu034@orion.oac.uci.edu (Carl F. Edman) Organization: University of California, Irvine Lines: 56 In article <26717@pasteur.Berkeley.EDU> krste@ICSI.Berkeley.EDU ( Krste Asanovic) writes: >Suggestion: If a function can be called with no arguments, then it >should be possible to call it without using the superfluous empty >parenthesis. E.g. > >class A >{ public: > A(int i = 0) { val = i; }; > int value() { return val; }; > private: > int val; >}; > >main() >{ > A a; > int b; > > b = a.value; > b = a.value(); // Still legal of course. >} > >It would appear that this would be a fairly minor change. It is >illegal to declare a variable and function with the same name in the >same scope, so there should be no ambiguity (or am I missing something >subtle in the parser?). This allows the user to ignore whether a data >member like object is implemented as a data member or as a member >function. It also saves a lot of ugly parens in code such as: > >foo.bar().far().boo() = foo2.bar3().far4().boo5() > >which might be written as > >foo.bar.far.boo = foo2.bar3.far4.boo5 > >Something similar already occurs in constructors, e.g. the definition >of "a" in main above. > A nice idea which I,too, have thought about before. It would f.e. let you define a second complex type in which the internal representation is in polar, not in cartesian coordinates. If you then decide that some comples variables in your program are almost exclusively multiplied and thus a polar representation would be more efficient, all you need to do is to change the declaration of the variable. Unfortunately, I do not think that this idea will ever be implemented, as foo.bar , where bar is a member function, already has a meaning. It denotes a pointer to the member function. Any programm which uses this (possibly not many) would break, if your suggestion were realized. Carl Edman Theorectial Physicist,N.:A physicist whose | Send mail existence is postulated, to make the numbers | to balance but who is never actually observed | cedman@golem.ps.uci.edu in the laboratory. | eapu034@orion.oac.uci.edu