stuct、class、typedef

1.typedef与操作符重载

struct Pseat{
    int x;
    int y;
    bool operator==(Pseat& rhs)
    {
        return x==rhs.x&&y==rhs.y;
    }   //操作符重载
};

写成typedef struct Pseat{...};也是正确的。

但如果写成下面的代码会报错:

typedef struct {
    int x;
    int y;
    bool operator==(Pseat& rhs)
    {
        return x==rhs.x&&y==rhs.y;
    }   //操作符重载
}Pseat;

 

2.类与结构体对象都是可以直接返回的

Pseat findNextSeat(Pseat cur,int di)  //结构体是可以直接返回的?
{
    Pseat nextSeat;
    if(di==1)
    {
        nextSeat.x=cur.x+1;
        nextSeat.y=cur.y;
    }
    return nextSeat;
}

该代码是正确的。

posted @ 2015-09-11 16:59  wy1290939507  阅读(297)  评论(0编辑  收藏  举报