#include<iostream>
    using namespace std;
    class Base{
    private:
    int x, y;
    const int p;
    public:
    Base(int m, int n, int d):p(d)  //通过初始化列表来获得初值
    {x=m; y=n;}
    void show();
    void show() const;
    };
    void Base::show()
    {cout<<x<<", "<<y<<"p="<<p<<endl;}
    void Base::show const
    {cout<<x<<", "<<y<<"const p="<<p<<endl;}
    void main(){
    Base a(1, 2, 3);
    const Base b(2, 1, 4);
    b.show();
    a.show();
    }
 
【正确答案】2,1,const p=4   1,2,p=3
【答案解析】 如果将一个对象说明为常对象,如对象b,则通过该对象只能调用它的const成员函数,不能调用其他成员函数。