C++ syntax

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; }

 

以上是关于C++ syntax的主要内容,如果未能解决你的问题,请参考以下文章