Suppose I have a base class with the following virtual function:
virtual int* get(){ return nullptr; }
and
I would like to supply a const version (bear in mind I have in ballpark of 50 different implementations in legacy code)
const int* get() const { return const_cast<decltype(this)>(this)->GetReturn(); };//NEED CODE BADLY: const_cast :/
But this idea needs to use a const_cast - scott meyer's suggest this approach in his book (albeit the situation is reversed) - but is it really safe (if yes, is it 'future-proof' as well?) from for example members being const ?
I can reverse the situation with some search/replace but having both implementations on all classes seems to be too much 'copy-paste' antipattern.