www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Signature of opAddAssign

reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
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.
Mar 02 2005
parent reply zwang <nehzgnaw gmail.com> writes:
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.
Mar 03 2005
parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
 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.
Mar 03 2005
parent "Andrew Fedoniouk" <news terrainformatica.com> writes:
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.
Mar 03 2005