programming:cpp:Cpp operator overloadingWhat links here?
http://www.cplusplus.com/doc/tutorial/classes2.html

type operator sign (parameters) { /*...*/ }

Here you have an example that overloads the addition operator (+). We are going to create a class to store bidimensional vectors and then we are going to add two of them: a(3,1) and b(1,2). The addition of two bidimensional vectors is an operation as simple as adding the two x coordinates to obtain the resulting x coordinate and adding the two y coordinates to obtain the resulting y. In this case the result will be (3+1,1+2) = (4,3).

// vectors: overloading operators example
  1. include using namespace std;


class my_vector { public: int x,y; my_vector () {} ; my_vector (int,int); my_vector operator + (my_vector); };

my_vector::my_vector (int a, int b) { x = a; y = b; }

my_vector my_vector::operator+ (my_vector param) { my_vector temp; temp.x = x + param.x; temp.y = y + param.y; return (temp); }

int main () { my_vector a (3,1); my_vector b (1,2); my_vector c; c = a + b; cout MALFORMED HTML TAG: << c.x << "," << c.y; return 0; }
programming:cpp:Cpp operator overloading
programming cgi
programming - sqlite3 - c interface - sqlite3_bind_int
programming:c:function gets
programming:c:function ferror
programming - javascript - onsubmit
programming - sqlite3 - c interface - sqlite3_bind_text
programming:c:function feof
programming - javascript - event handlers
programming:cpp
programming:windows:win32 structures
programming:c:function fread
programming:c:function strpos
programming:c:function utime
programming - pascal - procedure - str
programming:c:function fstat
programming - windows - CreateWindowEx
tk:tk_canvas
filename:programming:cpp:Cpp operator overloading
filename:programming%3Acpp%3ACpp%20operator%20overloading
last edit:September 09 2009 20:02:54 (5823 days ago)
ct = 1755697905.000000 = August 20 2025 09:51:45
ft = 1252540974.000000 = September 09 2009 20:02:54
dt = 503156931.000000