Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 03, 2005 Signature of opAddAssign | ||||
---|---|---|---|---|
| ||||
what is the proper way from D point of view? struct point { point opAddAssign(int i) { x += i; y += i; return make(x,y); } // --or just -- void opAddAssign(int i) { x += i; y += i; } } ( I am porting this into D http://www.terrainformatica.com/org/gool/geometry.h ) Andrew. |
March 03, 2005 Re: Signature of opAddAssign | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk | Andrew Fedoniouk wrote:
> what is the proper way from D point of view?
>
> struct point
> {
> point opAddAssign(int i) { x += i; y += i; return make(x,y); }
> // --or just --
> void opAddAssign(int i) { x += i; y += i; }
> }
>
> ( I am porting this into D
> http://www.terrainformatica.com/org/gool/geometry.h )
>
> Andrew.
>
>
IMO, I prefer the former which enables chained += operations.
|
March 03, 2005 Re: Signature of opAddAssign | ||||
---|---|---|---|---|
| ||||
Posted in reply to zwang | >> struct point
>> {
>> point opAddAssign(int i) { x += i; y += i; return make(x,y); }
>> // --or just --
>> void opAddAssign(int i) { x += i; y += i; }
>> }
>>
>
> IMO, I prefer the former which enables chained += operations.
Seems like my question was not clear enough....
Question is about compiler -
what code it produces on a += b ?
Compiler may suppres returning value of opAddAssign
and make value by its own. And that is the question.
As far as I understand there are no 'this' in struct methods (why?) so I cannot effectively return something like *this from methods. Am I right?
Andrew.
|
March 03, 2005 Re: Signature of opAddAssign | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk | Disregard my previous post. this in struct's works. Just tested it. Perfect. "Andrew Fedoniouk" <news@terrainformatica.com> wrote in message news:d07d6n$1st$1@digitaldaemon.com... >>> struct point >>> { >>> point opAddAssign(int i) { x += i; y += i; return make(x,y); } >>> // --or just -- >>> void opAddAssign(int i) { x += i; y += i; } >>> } >>> >> >> IMO, I prefer the former which enables chained += operations. > > Seems like my question was not clear enough.... > > Question is about compiler - > what code it produces on a += b ? > > Compiler may suppres returning value of opAddAssign > and make value by its own. And that is the question. > > As far as I understand there are no 'this' in struct methods (why?) so I cannot effectively return something like *this from methods. Am I right? > > Andrew. > > > > > > |
Copyright © 1999-2021 by the D Language Foundation