a const reference cant use the const pointer

struct A{
    void f(){

    }

    void f() const{

    }
};

struct B{
    void f1(){
        a->f();
    }

    void f1() const{
        a->f();
    }
    A *a;
};


int main(int argc, char *argv[])
{
    A a;
    B b;
    b.a = &a;
    b.f1();

    const B& d = b;
    d.f1();
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Janly/p/12431278.html