Hello,
I was just noticing that the 'const'ness of references often causes me to rewrite a large chunk of my code with pointers. For example if I have a class that needs access to a large amount of data from another class I would love to use a reference. However the only way to do that is to assign the references in the constructor (at least as far as I know) and therefore I can't re-assign the class at all (without complicated pointer conversions). As such I end up going through all my private data declarations and changing my references to pointers. This of course forces me to search my code for all the times I used the reference so that I can cast it. Not to mention that the class with all the data is for use by others, not by me (group project) and some of the others aren't yet comfortable enough with pointers to deal with them properly (Java programmers that just learned C++ in class). I was wondering if there is a way to say do this:
class someDataClass
{// private:
const largeDataType &data;
public:
someDataClass &setDataRef(const largeDataType &o){data@=o;}//new operator for reference copy?
};
Instead of having to do this:
class someDataClass
{// private:
const largeDataType *data;
public:
someDataClass &setDataRef(const largeDataType *o){data=o;}
};
I would have thought that if it wasn't possible that C++11 would have fixed that, given that it created the && move constructor, why couldn't it create some kind of reference re-assign operator?
PS: I see that a lot of people are already familiar with C++11 to the point that they don't think about it when they use its features. Is it now considered 'best practice' to use the new features? I am mainly concerned due to the lack of universal support for it and the fact that some C++ programmers have yet to learn the changes so I fear that C++11 code may not be understood.