如果函数不改变类的私有值,最好在函数声明和定义时在小括号后加 const class Stock{ private: int a_; public: Stock(int a){a_ = a; } void show() const;}Stock::show(){ using std::cout; using std::endl; cout << a_ << edl;}