vendredi 26 août 2016

How to initialize a non-const attribute of a const object with a const value?

I need to instantiate a const object of my class, and initialize its members pointers from const pointers. Is that possible? How to do it?

I have something of the kind:

class A:
    public Base
{
public:
    A():
        v(nullptr)
    {}

    virtual void f() override
    {}

private:
    my_type *v;

    friend void f(const my_type& orig)
    {
        // How to create a "const A" with "v == &my_type" ?
    }
};

Aucun commentaire:

Enregistrer un commentaire