012:这个指针哪来的

#include <iostream>
using namespace std;

struct A
{
    int v;
    A(int vv):v(vv) { }
// 在此处补充你的代码
    const A *getPointer() const {
        return this;
    }
};

int main()
{
    const A a(10);
    const A * p = a.getPointer();
    cout << p->v << endl;
    return 0;
}
const A *getPointer() const  第二个const是为什么

猜你喜欢

转载自www.cnblogs.com/zzsama/p/10797731.html