On May 20, 1:38*pm, thomas <freshtho...@gmail.com> wrote:
> Why do you want "local functions"(your words)?
Because sometimes the code in the local function is only applicable
(usable) from one function (and makes no sense from other contexts).
I've found that sometimes this prevents (local) code duplication.
Should I then now go and stick it in some unnamed namespace, think out
some name for it and confuse others as to its use, or would "local" be
more encapsulating?
> Maybe the only reanable explanation is avoiding polluting name space.
This would not be the case if we use an unnamed namespace, but our
name would have to be unique, not?
> Then declare a class wrapping your "MyFunction()" interface and make
> your local function private.
I hope you don't suggest that I should pollute my interface, which for
me is worse than polluting some namespace. Anything that need not be
in my interface should not be there. Perhaps a pimpl with access to
the this pointer would suffice as local (but still not local enough).
> Or define a new namespace.
> Either way is better than your "local function".
I for one, don't agree with this in all circumstances. I like Gert-
Jan's idiom and I've often used it.
Regards,
Werner
|