C++ syntax

new:

int *a = new int[size];

int **a = new int*[size];

 

运算符重载: //   输入输出运算符必须被重载为全局函数!

class Complex
{
    public:
        int a,b;
};

Complex operator+(Complex &x, Complex &y){ // x+y
    Complex c;
    c.a = x.a + y.a;
    c.b = x.b + y.b;
    return c;
}

ostream &operator<<(ostream &os, Complex &x){  //cout<<x<<endl;
    os<<x.a<<"+i"<<x.b;  
// this is to tell the compiler how to put a complex into the outputstream(ostream)
return os; }

 

posted @ 2016-01-24 08:50  飞飞喵  阅读(588)  评论(2编辑  收藏  举报