Topic: virtually typed return values [WAS: the most dissatisfying part of c++]


Author: rae@gpu.utcs.toronto.edu (Reid Ellis)
Date: 1 Aug 90 15:42:12 GMT
Raw View
schemers@vela.acs.oakland.edu (Roland Schemers III) writes:
|I understand your point of view though, and I think it would be nice
|if there was some construct in C++ to do what you want. I know some of
|my classes could use it. Maybe something like:
|
|class a {
|  public:
|    virtual& test() {
| // do some modification to the state of this object,
| // then ...
| return *this;
| }
|};
|
|In otherwords, make the return type 'virtual' like functions.

This is nice in that it uses an already key word.  However, this
would be too easily mixed up with people just forgetting to put
type names in their functions.  Rather than just

 virtual &method();

how about

 virtual class& method();

instead? "class" is already a keyword and it even sounds like what
it is -- a reference to the current "class".  But you're right,
this sounds like the syntax proposed for templates, so maybe they
will solve this problem without this changed syntax.

     Reid
--
Reid Ellis  264 Broadway Avenue, Toronto ON, M4P 1V9               Canada
rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu || +1 416 487 1383




Author: schemers@vela.acs.oakland.edu (Roland Schemers III)
Date: 2 Aug 90 18:03:14 GMT
Raw View
>
>|In otherwords, make the return type 'virtual' like functions.
>
>This is nice in that it uses an already key word.  However, this
>would be too easily mixed up with people just forgetting to put
>type names in their functions.
>

Yea, I realized the conflict with virtual functions after I sent the message.
Plus:
 virtual virtual&method();

Is quite ugly!!!!

>how about
>
> virtual class& method();
>
>instead? "class" is already a keyword and it even sounds like what

wouldn't this cause problems with functions like:

 virtual class X& method();

Where X is a class name? I'm not sure if this is legal syntax, but it
seems to me you should be able to qualify the X with the class keyword.


>But you're right, this sounds like the syntax proposed for templates,
> so maybe they will solve this problem without this changed syntax.
>

I hope templates solve this problem, if not, maybe a new keyword plus
some extra effort on the C++ translator/compiler is needed to solve this
problem!

>     Reid
>
>Reid Ellis  264 Broadway Avenue, Toronto ON, M4P 1V9               Canada
>rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu || +1 416 487 1383

--
Roland J. Schemers III                              Systems Programmer
schemers@vela.acs.oakland.edu (Ultrix)              Oakland University
schemers@argo.acs.oakland.edu (VMS)                 Rochester, MI 48309-4401
"Get off your LEF and do something!"                (313)-370-4323