c++ - Why Does Boost Use a Global Function Override to Implement Custom Validators in "Program Options" -


this example shows function named validate defined @ global scope overloading function in boost::program_options namespace.

what justifies design using global function overload? why more tightly-scoped design not implemented boost::program_options instead (e.g. overriding class method, or other scheme)?

as noted in comments below, main concern user might surprised find 1 of global functions being called library.

it should emphasized namespaced free functions extremely important (as opposed global-scope free functions, see this link provided chris drew). indeed, namespaced, non-class (free) functions imo major benefit of c++.

my company considering major adoption of boost, seems highly regarded. but, particular design decision has me concerned.

i think main surprise function defined in namespace can overloaded (hidden) function defined @ global scope. i'm going ask why c++ allows , whether considers flaw unless have brief explanation handy. user2141130 2 hours ago

no cannot considered flaw.

the function not hidden function defined @ global scope.

this argument dependent lookup (adl) for, , you've been using around! use here:

std::cout << "hello world!"; 

adl pretty subtle , pretty pervasive. many people don't realize until ask same kind of question asked. free function work nicely extension points.

more: what "argument-dependent lookup" (aka adl, or "koenig lookup")?


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -