Const

//返回引用型,并不是因为要返回引用型而是因为参数是引用型?返回的是实例的引用。*this===实例。那为什么一定要引用型呢?减少编译器开辟临时变量的消耗
Complex& Complex::operator =(const Complex& c)
{
    a = c.getA();
    b = c.getB();
    return *this;//为了连续等号
}
double Complex::getA()const
{
    return this->a;
}

对于const:

第一种情况,表示在函数中不能改变变量的属性

第二中情况,表示可以由类的常量来调用该函数

posted @ 2015-03-21 17:24  YORU  阅读(169)  评论(2编辑  收藏  举报