如果函数不改变类的私有值,最好在函数声明和定义时在小括号后加 const

    1. class Stock{
    2. private:
    3. int a_;
    4. public:
    5. Stock(int a){a_ = a; }
    6. void show() const;
    7. }
    8. Stock::show(){
    9. using std::cout;
    10. using std::endl;
    11. cout << a_ << edl;
    12. }