> I agree that const should be used for "logical constness". The rule should 
> not be merely "doesn't alter any data members of this object" but rather 
> "does not alter observable state of this object or vend any type of pointer 
> or reference by which observable state of this object could be altered".
> 
> Precisely!

I like this explanation too. 

I'm trying to think of a simple way to explain / test whether something falls 
into the category of logical constness, since it can be ambiguous.

It occurred to me that a simple, though imperfect, test is just, "Is this 
function called by an owner of a const pointer / reference?" After all, a const 
member function is meaningless if nobody points to the class through a const 
pointer  / reference. For classes like DOM and render tree nodes, which have no 
meaningful const-pointer-owning clients, the answer is always no. For other 
classes, the answer is yes, but only if someone has found a meaningful use for 
a const pointer or reference to the class.

So, perhaps the real style question we should answer is when to use const 
pointers / references, since the answer to when to use const member functions 
will follow from it.

What are some good examples of existing code that meaningfully uses a const 
pointer or reference? (Something other than, say, the obligatory const& in a 
copy constructor.)

Geoff
_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to