Hello
Lets say I have the following data structure:
Code:
class object {
public:
void some_function();
std::string get_something();
void set_something();
private:
//data
};
class main {
public:
main() : m_subclass(*this) { }
const object& get_object() { return m_object; }
private:
object m_object;
subclass m_subclass;
};
class subclass {
public:
subclass(main &obj) : m_object(obj.get_object()) { }
private:
object &m_object;
};
This will give an error because object in subclass is not const.
I've been told that its right to return references by const, but in that case I would have to store it in subclass as const object.. Do you guys store references by const / non-const or does it depend on situation?
Thanks a lot for help!