This may sound odd or just impossible...
I'm doing a lot of work with geometry-like user defined types (structures), for example
And I would be REALLY happy to be able to use syntax like this to operate on them:Code:struct point2d{double x,y;}; struct point3d{double x,y,z;};
Please notice:Code:point3d blah(point3d k); {return {k.x*2,k.y*2,k.z*2};} ... ... ... ... ... ... point3d t; t={0,0,0}; t=blah({1,1,1});
>the construct in the return statement of the function
>the assignment of t
>the function call
So far I'm aware that I can write
According to MSDN, this is called "aggregate type initialization" and I was very happy when I found it, believing that I found some alternative syntax that would help me construct types easily. But I was wrong, the syntax doesn't work in the above examples (I exposed three situations where I was expecting it to work).Code:struct point3d t={0,0,0};
So, why doesn't it work? What do you think I should do? So far I'm using these "constructor functions" that I made:
I'm very happy with these regarding the syntax, but ... I'm concerned that using them will slow down my calculations; and time is a problem.Code:point2d _stdcall fpoint2d(double x,double y) {struct point2d t={x,y}; return t;} point3d _stdcall fpoint3d(double x,double y,double z) {struct point3d t={x,y,z}; return t;}
Should I enhance the types to classes? Would'n that be slower? Should I use custom operators?
So, what are my options?



LinkBack URL
About LinkBacks


