"Howard" <al*****@hotmail.com> wrote in message
news:c6*******@dispatch.concentric.net...
"Dave" <be***********@yahoo.com> wrote in message
It works fine for me in my tests, but I'm curious as to why you'd ever
want to have a const and a non-const version of a function with the same name.
I would think that a function which modifies an object would tend to have an
"action" name, like SetTime, or UpdateParams or something, while a const
function would be more like Top or GetName.
-Howard
Actually, I don't want to name any of my methods with the same name. What I
want to do is parameterize a generic state space search library I'm writing
to use one of std::stack<>, std::queue<>, or std::priority_queue<>,
depending on the search technique to be used (std::stack<> results in
depth-first search, etc...). The problem is that the name of the method to
get the next element varies. For stack and priority_queue, it's top(). For
queue, it's front(). However, all of these methods have the same signature,
so I can use a pointer-to-member. That is as long as I select a const
method! priority_queue has only a const version, whereas stack and queue
have both const and non-const versions! So, I must be able to select either
at will. It was while working through all of this that I realized I could
use pointers to members to make my choice of which to call...