c++,c++11,smart-pointers,const-correctness
I'll answer in reverse order so to begin with the simple cases. Utility functions that accept objects from the factory functions, use them, but do not take ownership. (For example a function that counts the number of words in the document.) If you are calling a factory function, you are...
c++,visual-c++,c++11,const-correctness
Instead of using the _a data member directly create accessor functions with const and non-const overloads. This will cause the const overload to be selected when called from within const member functions of B, which in turn prevents you from calling non-const functions of A. A const& GetA() const {...
c,undefined-behavior,const-correctness,c89,pass-by-reference
There are two different sides related to const with a pointer S* p. Is it allowed to change the pointer? Example: p=5; Is it allowed to change the object pointed to? Example: p->x = 5; These are the four possibilities: T* p: both changes allowed const T* p: object...
Change your const_iterator to an iterator. Even if your Foo class doesn't directly modify the Bar object pointed to by the iterator, it still needs to have the right to modify it if it wants to grant that right to someone else. Which is what it's trying to do by...