|
|
|
|
|
by thisisnotatest
3977 days ago
|
|
const is type-incompatible like this: Suppose you want to write a function that returns all the nodes in a tree that satisfy some property. In C++ you have to define two different versions (or use templates to make the compiler clone it for you): vector<Node*> GetGoodNodes(Node* root);
vector<const Node*> GetGoodNodes(const Node* root);
If more than one type is involved in the operation, there can be a combinatorial explosion. |
|
Whenever I need to return a non-const reference/pointer to some inner data (which is not often) I name the method "mutableFoo()" to make clear what you're getting.
But most of the time (provided a sane API design) you won't have that problem anyway.