It's hell actually. Can someone please explain in plain English why the below segments work or not?
class Hey;
class Bitmap {
public:
const Hey* const& getHey() { return hey; }; // works
const Hey* & getHey2() { return hey; }; // error C2440: 'return' : cannot convert from 'Hey *' to 'const Hey *&'
private:
Hey* hey;
};
You can't add
constto a pointer more than one type deep which is not itselfconst, because then you could stuff the address of aconstvariable into a non-constpointer. Consider:Making the pointer
constprevents this disaster a different way. Continuing the example: