Код: Выделить всё
class A {
public:
int i = 0;
};
Код: Выделить всё
class B {
private:
A _a;
public:
A &getA(); // getter
};
Код: Выделить всё
constЯ хочу это разрешить:
Код: Выделить всё
B b;
b.getA().i = 1; // 1. WANTED behavior (allows member modification)
Код: Выделить всё
A otherA;
b.getA() = otherA; // 2. UNWANTED behavior (prevents copy assignment)
Подробнее здесь: https://stackoverflow.com/questions/798 ... nce-getter
Мобильная версия