C++中的运算符重载

/*
 * 运算符重载:函数重载的一种。
 */
#include <iostream>
using namespace std;
typedef struct
{
      double dx;
      double dy;
}S;
S operator+(S s1, S s2)
{
      S s3;
      s3.dx = s1.dx + s2.dx;
      s3.dy = s1.dy + s2.dy;
      return s3;
}
int main(int argc, char **argv)
{
      S s_1 = {1.1, 2.2};
      S s_2 = {3.3, 4.4};
      S s_3 = s_1 + s_2;
      cout << s_3.dx << endl << s_3.dy << endl;
      return 0;
}
 
本文来自CSDN博客,转载请标明出处: http://blog.csdn.net/programs/archive/2009/11/29/4901048.aspx

你可能感兴趣的:(职场,休闲)