lundi 11 novembre 2019

How to make a const getter for an arrray which contains another class's instances?

The problem is the getter has to work on const bar objects. But the compiler says: [Error] invalid conversion from 'const foo*' to 'foo*' [-fpermissive]

class foo{
private:
    string name;
public:
    foo(){
        name = "default";
    }
};

class bar{
    private:
foo array_of_foo[43];       
    public:
foo* get_array_of_foo() const {return array_of_foo;}
};

Aucun commentaire:

Enregistrer un commentaire