Operator keyword c++ -


we have following class. need explanation of parts of code.

class cpoint3d     {     public:       double x, y, z;        cpoint3d (double dx = 0.0, double dy = 0.0, double dz = 0.0)                : x(dx), y(dy), z(dz) {}       //what means these lines of    code?       cpoint3d operator + (const cpoint3d& point) const;       cpoint3d operator - (const cpoint3d& point) const;       cpoint3d operator * (double dfactor) const;       cpoint3d operator / (double dfactor) const; }; 

i guess using

cpoint3d operator + (const cpoint3d& point) const;

function can add/subtract/multiply/divide instances of cpoint3d class?

can explain examples ? thanks!

there millions of examples and/or articles of on web (including this one) won't re-iterate them here.

suffice when add 2 cpoint3d objects obj1 + obj2, function gets called operator+ class, 1 object being this , other being point.

your code responsible creating object containing addition of two, returning it.

ditto subtraction. multiplicative operators slightly different since use double other argument - presumably while makes sense add/subtract individual members of class additive operators, that's not useful multiplicative ones.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -